Uploading files using multipart form to Shopify files using Fastify multi-part

I'm using Fastify-multipart v5.3.1 with fastify v3 (for compatibility reasons) I use it to upload files from the client to the server and then from the server to Shopify.

From client to our server the files are transferred correctly but I'm having trouble with making a fetch call and appending the files to the formData (see the screenshot using fastify multipart). It throws an error in regards to not using a Blob. In my old approach (without using fastify) It seems that files[i].data holds the Buffer data which might be of type File which is allowed in the append method, but with Fastify I'm having trouble because the structure of the variable of files returned from .saveRequestFiles or when using parts is different.

I have been struggling with this issue for a while now and I'd appreciate the help.

Note: To understand exactly what I'm trying to do please check this doc on uploading files to Shopify: https://shopify.dev/docs/apps/online-store/media/products#step-2-add-media-to-a-product

enter image description here

enter image description here

enter image description here

Upvotes: 0

Views: 651

Answers (1)

Manuel Spigolon
Manuel Spigolon

Reputation: 12890

  • Reading the docs files[i].file does not exist.
  • Reading the code, files[i].file is a consumed readable stream, so you can't access it anymore

So if the saveRequestFiles() is used, it is needed to read the files[i].filepath to create a new Readable stream.

Upvotes: 0

Related Questions