File Upload with the REST API

Hello :wave:

When i trying to upload file with query param:

?overwrite=true

i got this error:

'Could not parse request with message: , status code 404, headers POST /D3D86A3D-6BA8-5838-FF44-774684333F00/console/files/upload/media/222d4e5a-36ac-4eda-9b1b-8b10b8e37c0e_1512489222298.jpg?overwrite=true'

It is worth mentioning when I make a request without this parameter the file is saved, but I need the ability to overwrite it

Request:

 POST http://localhost:9000/D3D86A3D-6BA8-5838-FF44-774684333F00/console/files/upload/media/222d4e5a-36ac-4eda-9b1b-8b10b8e37c0e_1512489222298.jpg?overwrite=true (err): 8.840ms

Code with request:

          const url = `${process.env.APIURL}/${process.env.APP_ID}/console/files/upload/${FOLDER}/${fileName}` 
          const firebaseReadableStream = await getStream(firebaseUrl)

          try {
            const { publicUrl } = await Backendless.Request.post(url)
              .set('Content-Type', 'multipart/form-data')
              .set('auth-key', authKey)
              .query({ overwrite: true })
              .form({ my_file: firebaseReadableStream, fileName })

            item[key] = publicUrl
          } catch (error) {
            console.log(error)
          }

Hi @Andrey_Varlamov,

Any particular reason you’re not using the API from the JS SDK?
https://backendless.com/docs/js/files_file_upload.html#non-blocking-api

Regards,
Mark

Hi Mark, I need pass readable stream to Backendless.Request

Would this work then?
https://backendless.com/docs/js/file_save_files_from_byte_arrays.html

1 Like

ok, i will try it.

Thanks!