Note: There's a similar question Upload image and metadata to arweave by using `@metaplex-foundation/js` whose accepted answer is "I tried it, it doesn't work, don't use metaplex to upload the image"
So, asking directly: Is it possible to upload an image to ARWeave using the metaplex JS SDK? Ie without making a second ARWeave client?
The Metaplex docs don't seem to have examples of uploading a binary (PNG, MP4 etc) using Metaplex with ARWeave storage.
The Solana Cookbook simply avoids using metaplex to upload the image at all:
const arweave = Arweave.init({
host: "arweave.net",
port: 443,
protocol: "https",
timeout: 20000,
logging: false,
});
// Upload image to Arweave
const data = fs.readFileSync("./code/nfts/arweave-upload/lowres-dog.png");
const transaction = await arweave.createTransaction({
data: data,
});
transaction.addTag("Content-Type", "image/png");
const wallet = JSON.parse(fs.readFileSync("wallet.json", "utf-8"))
await arweave.transactions.sign(transaction, wallet);
const response = await arweave.transactions.post(transaction);
console.log(response);
const id = transaction.id;
const imageUrl = id ? `https://arweave.net/${id}` : undefined;