how to send a POST request to download a file using rn-fetch-blob?JavaScript post request like a form submitHow can I upload files asynchronously?How to manage a redirect request after a jQuery Ajax callHow do I send a cross-domain POST request via JavaScript?How do I include a JavaScript file in another JavaScript file?JavaScript/jQuery to download file via POST with JSON dataHow to create a file in memory for user to download, but not through server?Use fetch to send get request with data objectBody not sent in “fetch” POST request and (my) solutionDownload file with rn-fetch-blob with POST

Is there a need for better software for writers?

What does i386 mean on macOS Mojave?

Does the 500 feet falling cap apply per fall, or per turn?

How can this pool heater gas line be disconnected?

How are Core iX names like Core i5, i7 related to Haswell, Ivy Bridge?

What is the difference between "Plural" and "Mehrzahl"?

What food production methods would allow a metropolis like New York to become self sufficient

Renting a house to a graduate student in my department

Ex-manager wants to stay in touch, I don't want to

Drawing perpendicular lines, filling areas

Can the sorting of a list be verified without comparing neighbors?

How old is Captain America at the end of "Avengers: Endgame"?

Will change of address affect direct deposit?

Was the Highlands Ranch shooting the 115th mass shooting in the US in 2019

Delta TSA-Precheck status removed

Looking for a simple way to manipulate one column of a matrix

Why do Thanos's punches not kill Captain America or at least cause some mortal injuries?

"Right on the tip of my tongue" meaning?

Why does the Earth follow an elliptical trajectory rather than a parabolic one?

Help decide course of action for rotting windows

Is there any evidence to support the claim that the United States was "suckered into WW1" by Zionists, made by Benjamin Freedman in his 1961 speech?

Was there ever any real use for a 6800-based Apple I?

Can you book a one-way ticket to the UK on a visa?

On what legal basis did the UK remove the 'European Union' from its passport?



how to send a POST request to download a file using rn-fetch-blob?


JavaScript post request like a form submitHow can I upload files asynchronously?How to manage a redirect request after a jQuery Ajax callHow do I send a cross-domain POST request via JavaScript?How do I include a JavaScript file in another JavaScript file?JavaScript/jQuery to download file via POST with JSON dataHow to create a file in memory for user to download, but not through server?Use fetch to send get request with data objectBody not sent in “fetch” POST request and (my) solutionDownload file with rn-fetch-blob with POST






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I'm using rn-fetch-blob library to download and save a file into the device, and I've been successful to do it with GET request like: .fetch('GET', "http://api.pdflayer.com/api/convert?access_key=MY_ACCESS_KEY&document_url=URL_PATH"), but the API that I use just accepts post request, so I tried this but didn't work:



const config, fs = RNFetchBlob;
let DownloadDir = fs.dirs.DownloadDir;
let options =
fileCache: true,
addAndroidDownloads :
useDownloadManager : true,
path: DownloadDir + "/file.pdf"

;
const data = JSON.stringify(
access_key: "MY_ACCESS_KEY",
document_url: "https://pdflayer.com/downloads/invoice.html"
);
config(options)
.fetch('POST', 'http://api.pdflayer.com/api/convert', body: data)
.then((res) =>
console.log(res);
)
.catch((err) =>
console.log(err)
)


If I'm not sending my request correctly, so how should I do it? thanks in advance.










share|improve this question




























    0















    I'm using rn-fetch-blob library to download and save a file into the device, and I've been successful to do it with GET request like: .fetch('GET', "http://api.pdflayer.com/api/convert?access_key=MY_ACCESS_KEY&document_url=URL_PATH"), but the API that I use just accepts post request, so I tried this but didn't work:



    const config, fs = RNFetchBlob;
    let DownloadDir = fs.dirs.DownloadDir;
    let options =
    fileCache: true,
    addAndroidDownloads :
    useDownloadManager : true,
    path: DownloadDir + "/file.pdf"

    ;
    const data = JSON.stringify(
    access_key: "MY_ACCESS_KEY",
    document_url: "https://pdflayer.com/downloads/invoice.html"
    );
    config(options)
    .fetch('POST', 'http://api.pdflayer.com/api/convert', body: data)
    .then((res) =>
    console.log(res);
    )
    .catch((err) =>
    console.log(err)
    )


    If I'm not sending my request correctly, so how should I do it? thanks in advance.










    share|improve this question
























      0












      0








      0








      I'm using rn-fetch-blob library to download and save a file into the device, and I've been successful to do it with GET request like: .fetch('GET', "http://api.pdflayer.com/api/convert?access_key=MY_ACCESS_KEY&document_url=URL_PATH"), but the API that I use just accepts post request, so I tried this but didn't work:



      const config, fs = RNFetchBlob;
      let DownloadDir = fs.dirs.DownloadDir;
      let options =
      fileCache: true,
      addAndroidDownloads :
      useDownloadManager : true,
      path: DownloadDir + "/file.pdf"

      ;
      const data = JSON.stringify(
      access_key: "MY_ACCESS_KEY",
      document_url: "https://pdflayer.com/downloads/invoice.html"
      );
      config(options)
      .fetch('POST', 'http://api.pdflayer.com/api/convert', body: data)
      .then((res) =>
      console.log(res);
      )
      .catch((err) =>
      console.log(err)
      )


      If I'm not sending my request correctly, so how should I do it? thanks in advance.










      share|improve this question














      I'm using rn-fetch-blob library to download and save a file into the device, and I've been successful to do it with GET request like: .fetch('GET', "http://api.pdflayer.com/api/convert?access_key=MY_ACCESS_KEY&document_url=URL_PATH"), but the API that I use just accepts post request, so I tried this but didn't work:



      const config, fs = RNFetchBlob;
      let DownloadDir = fs.dirs.DownloadDir;
      let options =
      fileCache: true,
      addAndroidDownloads :
      useDownloadManager : true,
      path: DownloadDir + "/file.pdf"

      ;
      const data = JSON.stringify(
      access_key: "MY_ACCESS_KEY",
      document_url: "https://pdflayer.com/downloads/invoice.html"
      );
      config(options)
      .fetch('POST', 'http://api.pdflayer.com/api/convert', body: data)
      .then((res) =>
      console.log(res);
      )
      .catch((err) =>
      console.log(err)
      )


      If I'm not sending my request correctly, so how should I do it? thanks in advance.







      javascript react-native fetch






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 23 at 10:46









      Blue TurtleBlue Turtle

      8319




      8319






















          1 Answer
          1






          active

          oldest

          votes


















          1














          According to the rn-fetch-blob's document :




          headers:object (Optional) Headers of HTTP request, the value of
          headers should be stringified, if you're uploading binary files,
          content-type should be application/octet-stream or
          multipart/form-data(see examples above).



          body:string | Array (Optional) Body of the HTTP request, body
          can either be a BASE64 string, or an array contains object elements,
          each element have 2 required property name, data, and optional
          property filename, once filename is set, content in data property will
          be considered as a path to a file or a BASE64 string which will be
          converted into byte array later.




          I think you should define content-type for your request and change your code like these examples :



          // Post binary data using base64 encoding
          RNFetchBlob.fetch('POST', 'http://myupload.com/upload',
          'Content-Type' : 'application/octet-stream'
          , RNFetchBlob.base64.encode(mydata))

          // Post binary data from existing file
          RNFetchBlob.fetch('POST', 'http://myupload.com/upload',
          'Content-Type' : 'application/octet-stream'
          , RNFetchBlob.wrap(path_to_the_file))

          // Post form data
          RNFetchBlob.fetch('POST', 'http://myupload.com/upload',
          'Content-Type' : 'multipart/form-data'
          , [
          name : 'user_name', data : 'Bill' ,
          // binary field data from a file path, use `wrap` method to wrap the path
          name : 'avatar', filename : 'avatar.jpg', data : RNFetchBlob.wrap(path_to_the_file) ,
          // binary field data encoded in BASE64
          name : 'pet-avatar', filename : 'pet-avatar.jpg', data : RNFetchBlob.base64.encode(image_data) ,
          ])


          I hope that helps :)






          share|improve this answer























          • @BlueTurtle change your content-type to "multipart/form-data"

            – blkrt
            Mar 23 at 11:49











          • I did, but nothing changed!, I've tested this API in postman and I could send a post request with exactly the same data and getting a file, I'm sure there is something wrong with my request

            – Blue Turtle
            Mar 23 at 11:50












          • do you know any alternative library that can do what I need?

            – Blue Turtle
            Mar 23 at 12:06












          • @BlueTurtle Maybe your problem is related to something else, however, you could use XMLHttpRequest, Frisbee or axios library instead.

            – blkrt
            Mar 23 at 12:15











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55312896%2fhow-to-send-a-post-request-to-download-a-file-using-rn-fetch-blob%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          According to the rn-fetch-blob's document :




          headers:object (Optional) Headers of HTTP request, the value of
          headers should be stringified, if you're uploading binary files,
          content-type should be application/octet-stream or
          multipart/form-data(see examples above).



          body:string | Array (Optional) Body of the HTTP request, body
          can either be a BASE64 string, or an array contains object elements,
          each element have 2 required property name, data, and optional
          property filename, once filename is set, content in data property will
          be considered as a path to a file or a BASE64 string which will be
          converted into byte array later.




          I think you should define content-type for your request and change your code like these examples :



          // Post binary data using base64 encoding
          RNFetchBlob.fetch('POST', 'http://myupload.com/upload',
          'Content-Type' : 'application/octet-stream'
          , RNFetchBlob.base64.encode(mydata))

          // Post binary data from existing file
          RNFetchBlob.fetch('POST', 'http://myupload.com/upload',
          'Content-Type' : 'application/octet-stream'
          , RNFetchBlob.wrap(path_to_the_file))

          // Post form data
          RNFetchBlob.fetch('POST', 'http://myupload.com/upload',
          'Content-Type' : 'multipart/form-data'
          , [
          name : 'user_name', data : 'Bill' ,
          // binary field data from a file path, use `wrap` method to wrap the path
          name : 'avatar', filename : 'avatar.jpg', data : RNFetchBlob.wrap(path_to_the_file) ,
          // binary field data encoded in BASE64
          name : 'pet-avatar', filename : 'pet-avatar.jpg', data : RNFetchBlob.base64.encode(image_data) ,
          ])


          I hope that helps :)






          share|improve this answer























          • @BlueTurtle change your content-type to "multipart/form-data"

            – blkrt
            Mar 23 at 11:49











          • I did, but nothing changed!, I've tested this API in postman and I could send a post request with exactly the same data and getting a file, I'm sure there is something wrong with my request

            – Blue Turtle
            Mar 23 at 11:50












          • do you know any alternative library that can do what I need?

            – Blue Turtle
            Mar 23 at 12:06












          • @BlueTurtle Maybe your problem is related to something else, however, you could use XMLHttpRequest, Frisbee or axios library instead.

            – blkrt
            Mar 23 at 12:15















          1














          According to the rn-fetch-blob's document :




          headers:object (Optional) Headers of HTTP request, the value of
          headers should be stringified, if you're uploading binary files,
          content-type should be application/octet-stream or
          multipart/form-data(see examples above).



          body:string | Array (Optional) Body of the HTTP request, body
          can either be a BASE64 string, or an array contains object elements,
          each element have 2 required property name, data, and optional
          property filename, once filename is set, content in data property will
          be considered as a path to a file or a BASE64 string which will be
          converted into byte array later.




          I think you should define content-type for your request and change your code like these examples :



          // Post binary data using base64 encoding
          RNFetchBlob.fetch('POST', 'http://myupload.com/upload',
          'Content-Type' : 'application/octet-stream'
          , RNFetchBlob.base64.encode(mydata))

          // Post binary data from existing file
          RNFetchBlob.fetch('POST', 'http://myupload.com/upload',
          'Content-Type' : 'application/octet-stream'
          , RNFetchBlob.wrap(path_to_the_file))

          // Post form data
          RNFetchBlob.fetch('POST', 'http://myupload.com/upload',
          'Content-Type' : 'multipart/form-data'
          , [
          name : 'user_name', data : 'Bill' ,
          // binary field data from a file path, use `wrap` method to wrap the path
          name : 'avatar', filename : 'avatar.jpg', data : RNFetchBlob.wrap(path_to_the_file) ,
          // binary field data encoded in BASE64
          name : 'pet-avatar', filename : 'pet-avatar.jpg', data : RNFetchBlob.base64.encode(image_data) ,
          ])


          I hope that helps :)






          share|improve this answer























          • @BlueTurtle change your content-type to "multipart/form-data"

            – blkrt
            Mar 23 at 11:49











          • I did, but nothing changed!, I've tested this API in postman and I could send a post request with exactly the same data and getting a file, I'm sure there is something wrong with my request

            – Blue Turtle
            Mar 23 at 11:50












          • do you know any alternative library that can do what I need?

            – Blue Turtle
            Mar 23 at 12:06












          • @BlueTurtle Maybe your problem is related to something else, however, you could use XMLHttpRequest, Frisbee or axios library instead.

            – blkrt
            Mar 23 at 12:15













          1












          1








          1







          According to the rn-fetch-blob's document :




          headers:object (Optional) Headers of HTTP request, the value of
          headers should be stringified, if you're uploading binary files,
          content-type should be application/octet-stream or
          multipart/form-data(see examples above).



          body:string | Array (Optional) Body of the HTTP request, body
          can either be a BASE64 string, or an array contains object elements,
          each element have 2 required property name, data, and optional
          property filename, once filename is set, content in data property will
          be considered as a path to a file or a BASE64 string which will be
          converted into byte array later.




          I think you should define content-type for your request and change your code like these examples :



          // Post binary data using base64 encoding
          RNFetchBlob.fetch('POST', 'http://myupload.com/upload',
          'Content-Type' : 'application/octet-stream'
          , RNFetchBlob.base64.encode(mydata))

          // Post binary data from existing file
          RNFetchBlob.fetch('POST', 'http://myupload.com/upload',
          'Content-Type' : 'application/octet-stream'
          , RNFetchBlob.wrap(path_to_the_file))

          // Post form data
          RNFetchBlob.fetch('POST', 'http://myupload.com/upload',
          'Content-Type' : 'multipart/form-data'
          , [
          name : 'user_name', data : 'Bill' ,
          // binary field data from a file path, use `wrap` method to wrap the path
          name : 'avatar', filename : 'avatar.jpg', data : RNFetchBlob.wrap(path_to_the_file) ,
          // binary field data encoded in BASE64
          name : 'pet-avatar', filename : 'pet-avatar.jpg', data : RNFetchBlob.base64.encode(image_data) ,
          ])


          I hope that helps :)






          share|improve this answer













          According to the rn-fetch-blob's document :




          headers:object (Optional) Headers of HTTP request, the value of
          headers should be stringified, if you're uploading binary files,
          content-type should be application/octet-stream or
          multipart/form-data(see examples above).



          body:string | Array (Optional) Body of the HTTP request, body
          can either be a BASE64 string, or an array contains object elements,
          each element have 2 required property name, data, and optional
          property filename, once filename is set, content in data property will
          be considered as a path to a file or a BASE64 string which will be
          converted into byte array later.




          I think you should define content-type for your request and change your code like these examples :



          // Post binary data using base64 encoding
          RNFetchBlob.fetch('POST', 'http://myupload.com/upload',
          'Content-Type' : 'application/octet-stream'
          , RNFetchBlob.base64.encode(mydata))

          // Post binary data from existing file
          RNFetchBlob.fetch('POST', 'http://myupload.com/upload',
          'Content-Type' : 'application/octet-stream'
          , RNFetchBlob.wrap(path_to_the_file))

          // Post form data
          RNFetchBlob.fetch('POST', 'http://myupload.com/upload',
          'Content-Type' : 'multipart/form-data'
          , [
          name : 'user_name', data : 'Bill' ,
          // binary field data from a file path, use `wrap` method to wrap the path
          name : 'avatar', filename : 'avatar.jpg', data : RNFetchBlob.wrap(path_to_the_file) ,
          // binary field data encoded in BASE64
          name : 'pet-avatar', filename : 'pet-avatar.jpg', data : RNFetchBlob.base64.encode(image_data) ,
          ])


          I hope that helps :)







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 23 at 11:17









          blkrtblkrt

          1494




          1494












          • @BlueTurtle change your content-type to "multipart/form-data"

            – blkrt
            Mar 23 at 11:49











          • I did, but nothing changed!, I've tested this API in postman and I could send a post request with exactly the same data and getting a file, I'm sure there is something wrong with my request

            – Blue Turtle
            Mar 23 at 11:50












          • do you know any alternative library that can do what I need?

            – Blue Turtle
            Mar 23 at 12:06












          • @BlueTurtle Maybe your problem is related to something else, however, you could use XMLHttpRequest, Frisbee or axios library instead.

            – blkrt
            Mar 23 at 12:15

















          • @BlueTurtle change your content-type to "multipart/form-data"

            – blkrt
            Mar 23 at 11:49











          • I did, but nothing changed!, I've tested this API in postman and I could send a post request with exactly the same data and getting a file, I'm sure there is something wrong with my request

            – Blue Turtle
            Mar 23 at 11:50












          • do you know any alternative library that can do what I need?

            – Blue Turtle
            Mar 23 at 12:06












          • @BlueTurtle Maybe your problem is related to something else, however, you could use XMLHttpRequest, Frisbee or axios library instead.

            – blkrt
            Mar 23 at 12:15
















          @BlueTurtle change your content-type to "multipart/form-data"

          – blkrt
          Mar 23 at 11:49





          @BlueTurtle change your content-type to "multipart/form-data"

          – blkrt
          Mar 23 at 11:49













          I did, but nothing changed!, I've tested this API in postman and I could send a post request with exactly the same data and getting a file, I'm sure there is something wrong with my request

          – Blue Turtle
          Mar 23 at 11:50






          I did, but nothing changed!, I've tested this API in postman and I could send a post request with exactly the same data and getting a file, I'm sure there is something wrong with my request

          – Blue Turtle
          Mar 23 at 11:50














          do you know any alternative library that can do what I need?

          – Blue Turtle
          Mar 23 at 12:06






          do you know any alternative library that can do what I need?

          – Blue Turtle
          Mar 23 at 12:06














          @BlueTurtle Maybe your problem is related to something else, however, you could use XMLHttpRequest, Frisbee or axios library instead.

          – blkrt
          Mar 23 at 12:15





          @BlueTurtle Maybe your problem is related to something else, however, you could use XMLHttpRequest, Frisbee or axios library instead.

          – blkrt
          Mar 23 at 12:15



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55312896%2fhow-to-send-a-post-request-to-download-a-file-using-rn-fetch-blob%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript