将此cURL转换为纯JavaScript

时间:2017-04-24 13:59:04

标签: javascript curl

我想将以下cURL命令转换为纯JS:

curl -X POST \
-H "Content-Type: image/jpeg" \
--data-binary '@myPicture.jpg' \
https://parseapi.back4app.com/files/pic.jpg

到目前为止,我能够做到以下几点:

  let postUrl = 'https://parseapi.back4app.com/files/'+picUrl;
  ParseHeaders.append('Content-Type', 'image/jpeg');
  return this.http.post(postUrl, {"name": "anything.jpg"}, {headers: ParseHeaders})
             .subscribe(
  (body:any) => {

    let res = JSON.parse(body._body);

  },
    error => console.log(error.json())
  );

但是,就我认为我需要转换--data-binary以使其正常工作而言,它对我来说并不起作用!

0 个答案:

没有答案