0

I'm using Postman and trying to send a POST request to an API with an image, one of the required parameters to do so is a file "Base 64 encoded file content string. Maximum file size to upload 5Mb". Not sure what else I can try.

the example they give in the documentation is:

"file": "https://example.com/image.png"

*from:

curl -i -u <api_username>:<api_password> -H "Content-type: application/json" -H "Security-Key: <your_private_key>" -XPOST https://api2.questblue.com/fax/send -d "{"did_from": 3332224444, "did_to": 1112223333, "file": "https://example.com/image.png"}"

I tried uploading a test image to a image hosting site then included its link that but got: "error": "File Type is not Supported" (My test image was also a png) filetypes accepted are:(string)jpeg, jpg, gif, png, tif, tiff, pdf, doc, rtf, ods, xls, csv, ppt, txt, rar, zip, 7z4

I've also tried running my test image through https://www.base64decode.org/ then used the string it output but received an error saying URI was to long.

*I also just tried uploading the file, got the same File Type is not Supported error:

var fs = require('fs');
var options = {
  'method': 'POST',
  'url': 'https://api2.questblue.com/fax/send',
  'headers': {
    'Content-type': 'application/json',
    'Security-Key': 'key',
    'Authorization': 'auth'
  },
  formData: {
    'did_from': 3332224444,
    'did_to': 1112223333,
    'filename': 'testfax',
    'file': {
      'value': fs.createReadStream('C:/Users/zee/folder/testfax.jpg'),
      'options': {
        'filename': 'C:/Users/zee/folder/testfax.jpg',
        'contentType': null
      }
    }
  }
};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});```
Zee
  • 1
  • 1
  • Hard to say because you're not including any code. The description you give "Base64 encoded file content string" and the example you gave also contradict, so perhaps the documentation is wrong. – Evert Nov 04 '21 at 05:08
  • If you are sending a POST request, then you shouldn't get the error "URI was to long" because that data should be in the request body and _not_ the request URI. It sounds like you aren't putting that base 64 encoded string in the right spot. – Alex Wayne Nov 04 '21 at 06:03
  • The documentation's example is sending an URL, not a local file path. Maybe it's an error or maybe it's an undocumented feature. either way, sending a local path obviously won't work. And nowhere in your code you actually attempted to encode the file into base64. – gre_gor Nov 04 '21 at 06:04
  • Does this answer your question? [ReadFile in Base64 Nodejs](https://stackoverflow.com/questions/28834835/readfile-in-base64-nodejs) – gre_gor Nov 04 '21 at 06:10
  • Please provide enough code so others can better understand or reproduce the problem. – Community Nov 04 '21 at 15:21

0 Answers0