Downloading a file using the PUT method in response mode

I am trying to upload a file (image) from my responsive application to the backend server. The RESTFUL backend server accepts file transfers via the PUT method at a specific URL. I am stuck in native-native trying to find the correct way to send a file using the PUT method.

I am trying to reproduce the behavior.
curl -X PUT -T "/path/to/file" "http://myputserver.com/puturl.tmp"

I found the XMLHttpRequest method for this in the browser, but will not work on native-native. Has anyone gone through this, please help !!!

+4
source share
3 answers

Fetch

fetch api, React Native. .

Fetch PUT, .

fetch('https://mywebsite.com/endpoint/', {
  method: 'PUT',
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    firstParam: 'yourValue',
    secondParam: 'yourOtherValue',
  })
})
+1

PUT . , "Content-Type": "multipart/form-data;".

 const config = {
     method: 'PUT',
     headers: {
       'Accept': 'application/json',
       'Content-Type': 'multipart/form-data;',
       'Authorization': 'Bearer ' + 'SECRET_OAUTH2_TOKEN_IF_AUTH',
     },
     body: data,
    }

: http://snowball.digital/Blog/Uploading-Images-in-React-Native

0
fetch('https://mywebsite.com/endpoint/', {
  method: 'PUT',
  headers: {
    Accept: 'application/json',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    firstParam: 'yourValue',
    secondParam: 'yourOtherValue',
  }),
})
.then((response) => response.json())
.then((responseJson) => {
   alert(responseJson)
})
.catch((error) => {
 console.error(error)
})

link
 link 2

0
source

All Articles