w3up icon indicating copy to clipboard operation
w3up copied to clipboard

How to use pre-existing space for uploading files on web3.storage

Open Mihir02 opened this issue 9 months ago • 1 comments

`import { create } from '@web3-storage/w3up-client'

export const IPFS_GATEWAY = "https://ipfs.io/ipfs/";

export const ipfsSaveContent = async (files) => { const client = await create()

// get an email to use for the w3up account that will control the space
const inputEmail = process.env.Email

// account associated with input email
let myAccount
if (inputEmail) {
console.warn(`about to w3up client.login with email ${inputEmail}`)
myAccount = await client.login(inputEmail)
}

const sharkDaoSpace = await client.createSpace('sharkDAO.xyz')

// console.log('sharkDaoSpace', sharkDaoSpace)

if (myAccount) {
console.warn(`account ${myAccount.did()} is adding a provider to space ${sharkDaoSpace.did()}`)
await myAccount.provision(sharkDaoSpace.did())
}

// this is what was missing but I didn't know it at the time
await client.addSpace(await sharkDaoSpace.createAuthorization(client))
await client.setCurrentSpace(sharkDaoSpace.did())
const sharkPics = await client.uploadDirectory([files])

await sharkDaoSpace.save()
console.log(sharkPics.toString())

return sharkPics.toString();

}; `

I want to use a pre-existing space that I created manually on web3.storage console. For now, this is the only way I know to upload files successfully on different spaces apparently linked to my account, which is not showing up on my console. web3

Mihir02 avatar May 09 '24 09:05 Mihir02

If I understand your question correctly, you want to use a space that was created via your console. Maybe try using account.provision? Copy the space did from your console and do await account.provision(spaceDid). spaceDid is a string.

aarontravass avatar Jul 06 '24 03:07 aarontravass