I wanted to ask If for example I have an image link(imgur.com etc) and I wish to use that as the Metadata for my NFT. Would that be possible?
I tried doing that:
const metaplex = Metaplex.make(connection)
.use(keypairIdentity(user))
.use(
bundlrStorage({
address: "https://devnet.bundlr.network",
providerUrl: "https://api.devnet.solana.com",
timeout: 60000,
})
)
const request = require('request');
let file: any;
const sharp = require('sharp');
const fs = require('fs');
console.log("reached here")
const imageUrl = 'https://imgur.com/gallery/vQk9HuN';
fs.readFile(imageUrl, (err: Error | null, data: Buffer | ArrayBuffer | SharedArrayBuffer) => {~
console.log("2nd destination")
if (err) {
// handle the error
} else {
// Convert the data into a buffer
const buffer = Buffer.from(data);
// Convert the buffer into a Metaplex file
const file = toMetaplexFile(buffer, "image.png");
}
console.log(data)
});
// Wait for the file to be assigned a value
await new Promise((resolve) => {
const checkFile = setInterval(() => {
if (file) {
clearInterval(checkFile);
resolve(file);
}
}, 1);
});
// Use the file variable here
const imageUri = await metaplex.storage().upload(file)
console.log("image uri:", imageUri)
When I do not "await new Promise" I get this error: TypeError: Cannot read properties of undefined (reading 'buffer') at reduce (/home/harry_smith/bld/[name]/node_modules/@metaplex-foundation/js/src/plugins/storageModule/MetaplexFile.ts:77:42) at Array.reduce () at Object.getBytesFromMetaplexFiles (/home/harry_smith/bld/[name]/node_modules/@metaplex-foundation/js/src/plugins/storageModule/MetaplexFile.ts:77:9) at BundlrStorageDriver.uploadAll (/home/harry_smith/bld/[name]/node_modules/@metaplex-foundation/js/src/plugins/bundlrStorage/BundlrStorageDriver.ts:109:7) at processTicksAndRejections (node:internal/process/task_queues:95:5) at async BundlrStorageDriver.upload (/home/harry_smith/bld/[name]/node_modules/@metaplex-foundation/js/src/plugins/bundlrStorage/BundlrStorageDriver.ts:101:19)
however, when I use it then my terminal is just stuck. it does not show any error but it does not move forward either after console logging my public key and balance. Is it possible to do what I am trying to do? @Metaplex devs.