File API - works with cURL but fails with AJAX and Postman
I am running gotenberg
as my document to PDF conversion API
and it is working with cURL
.
The cURL
command looks like this
curl --request POST --url http://example.com --header 'Content-Type: multipart/form-data' --form files=@file.docx > result.pdf
The API
works only with cURL
, When i try hitting the same API
with Postman
or AJAX
i get a response but on saving the details or by previewing the response using Postman
i get an empty PDF file.
My AJAX
request looks like this
var settings = {
"async": true,
"crossDomain": true,
"url": "http://convertionapi.com",
"method": "POST",
"processData": false,
"contentType": false,
"data": form,
success: function(data){
console.log("Success", data);
s3.upload({
Key: "files/test.pdf",
Body: data,
ContentType: 'application/pdf',
ACL: 'public-read',
},function(err, data) {...}
},
error: function(err) {
console.log("Error", err);
}
}
Can anyone throw some light as to what is happening with my request?
I get the below headers with my response but the created files are empty
jquery ajax curl
|
show 5 more comments
I am running gotenberg
as my document to PDF conversion API
and it is working with cURL
.
The cURL
command looks like this
curl --request POST --url http://example.com --header 'Content-Type: multipart/form-data' --form files=@file.docx > result.pdf
The API
works only with cURL
, When i try hitting the same API
with Postman
or AJAX
i get a response but on saving the details or by previewing the response using Postman
i get an empty PDF file.
My AJAX
request looks like this
var settings = {
"async": true,
"crossDomain": true,
"url": "http://convertionapi.com",
"method": "POST",
"processData": false,
"contentType": false,
"data": form,
success: function(data){
console.log("Success", data);
s3.upload({
Key: "files/test.pdf",
Body: data,
ContentType: 'application/pdf',
ACL: 'public-read',
},function(err, data) {...}
},
error: function(err) {
console.log("Error", err);
}
}
Can anyone throw some light as to what is happening with my request?
I get the below headers with my response but the created files are empty
jquery ajax curl
1
What are you getting in the console.log, when you write "Success" + data?
– Brank Victoria
Nov 22 '18 at 9:06
I am getting like this imgur.com/a/hfPQdWB
– Nithin
Nov 22 '18 at 9:22
1
Then, it seems that you are getting correctly the PDF from the ajax request. Now what you need to do with that information? Download it?
– Brank Victoria
Nov 22 '18 at 9:24
I am trying to save the PDF to S3 and a PDF is being created on S3, but the entire PDF is just one empty file, by empty file i mean there is no content just plain A4 sheets :/
– Nithin
Nov 22 '18 at 9:25
I have no idea of what S3 is. Just in case, are you able to see the size of the file created in S3? Is it 51563 bytes? Or it is 0bytes?
– Brank Victoria
Nov 22 '18 at 9:27
|
show 5 more comments
I am running gotenberg
as my document to PDF conversion API
and it is working with cURL
.
The cURL
command looks like this
curl --request POST --url http://example.com --header 'Content-Type: multipart/form-data' --form files=@file.docx > result.pdf
The API
works only with cURL
, When i try hitting the same API
with Postman
or AJAX
i get a response but on saving the details or by previewing the response using Postman
i get an empty PDF file.
My AJAX
request looks like this
var settings = {
"async": true,
"crossDomain": true,
"url": "http://convertionapi.com",
"method": "POST",
"processData": false,
"contentType": false,
"data": form,
success: function(data){
console.log("Success", data);
s3.upload({
Key: "files/test.pdf",
Body: data,
ContentType: 'application/pdf',
ACL: 'public-read',
},function(err, data) {...}
},
error: function(err) {
console.log("Error", err);
}
}
Can anyone throw some light as to what is happening with my request?
I get the below headers with my response but the created files are empty
jquery ajax curl
I am running gotenberg
as my document to PDF conversion API
and it is working with cURL
.
The cURL
command looks like this
curl --request POST --url http://example.com --header 'Content-Type: multipart/form-data' --form files=@file.docx > result.pdf
The API
works only with cURL
, When i try hitting the same API
with Postman
or AJAX
i get a response but on saving the details or by previewing the response using Postman
i get an empty PDF file.
My AJAX
request looks like this
var settings = {
"async": true,
"crossDomain": true,
"url": "http://convertionapi.com",
"method": "POST",
"processData": false,
"contentType": false,
"data": form,
success: function(data){
console.log("Success", data);
s3.upload({
Key: "files/test.pdf",
Body: data,
ContentType: 'application/pdf',
ACL: 'public-read',
},function(err, data) {...}
},
error: function(err) {
console.log("Error", err);
}
}
Can anyone throw some light as to what is happening with my request?
I get the below headers with my response but the created files are empty
jquery ajax curl
jquery ajax curl
asked Nov 22 '18 at 8:55
NithinNithin
318112
318112
1
What are you getting in the console.log, when you write "Success" + data?
– Brank Victoria
Nov 22 '18 at 9:06
I am getting like this imgur.com/a/hfPQdWB
– Nithin
Nov 22 '18 at 9:22
1
Then, it seems that you are getting correctly the PDF from the ajax request. Now what you need to do with that information? Download it?
– Brank Victoria
Nov 22 '18 at 9:24
I am trying to save the PDF to S3 and a PDF is being created on S3, but the entire PDF is just one empty file, by empty file i mean there is no content just plain A4 sheets :/
– Nithin
Nov 22 '18 at 9:25
I have no idea of what S3 is. Just in case, are you able to see the size of the file created in S3? Is it 51563 bytes? Or it is 0bytes?
– Brank Victoria
Nov 22 '18 at 9:27
|
show 5 more comments
1
What are you getting in the console.log, when you write "Success" + data?
– Brank Victoria
Nov 22 '18 at 9:06
I am getting like this imgur.com/a/hfPQdWB
– Nithin
Nov 22 '18 at 9:22
1
Then, it seems that you are getting correctly the PDF from the ajax request. Now what you need to do with that information? Download it?
– Brank Victoria
Nov 22 '18 at 9:24
I am trying to save the PDF to S3 and a PDF is being created on S3, but the entire PDF is just one empty file, by empty file i mean there is no content just plain A4 sheets :/
– Nithin
Nov 22 '18 at 9:25
I have no idea of what S3 is. Just in case, are you able to see the size of the file created in S3? Is it 51563 bytes? Or it is 0bytes?
– Brank Victoria
Nov 22 '18 at 9:27
1
1
What are you getting in the console.log, when you write "Success" + data?
– Brank Victoria
Nov 22 '18 at 9:06
What are you getting in the console.log, when you write "Success" + data?
– Brank Victoria
Nov 22 '18 at 9:06
I am getting like this imgur.com/a/hfPQdWB
– Nithin
Nov 22 '18 at 9:22
I am getting like this imgur.com/a/hfPQdWB
– Nithin
Nov 22 '18 at 9:22
1
1
Then, it seems that you are getting correctly the PDF from the ajax request. Now what you need to do with that information? Download it?
– Brank Victoria
Nov 22 '18 at 9:24
Then, it seems that you are getting correctly the PDF from the ajax request. Now what you need to do with that information? Download it?
– Brank Victoria
Nov 22 '18 at 9:24
I am trying to save the PDF to S3 and a PDF is being created on S3, but the entire PDF is just one empty file, by empty file i mean there is no content just plain A4 sheets :/
– Nithin
Nov 22 '18 at 9:25
I am trying to save the PDF to S3 and a PDF is being created on S3, but the entire PDF is just one empty file, by empty file i mean there is no content just plain A4 sheets :/
– Nithin
Nov 22 '18 at 9:25
I have no idea of what S3 is. Just in case, are you able to see the size of the file created in S3? Is it 51563 bytes? Or it is 0bytes?
– Brank Victoria
Nov 22 '18 at 9:27
I have no idea of what S3 is. Just in case, are you able to see the size of the file created in S3? Is it 51563 bytes? Or it is 0bytes?
– Brank Victoria
Nov 22 '18 at 9:27
|
show 5 more comments
1 Answer
1
active
oldest
votes
I needed to handle blob
response and thus my AJAX
call must have looked like this.
var settings = {
"async": true,
"crossDomain": true,
"url": "http://convertionapi.com",
"method": "POST",
"processData": false,
"contentType": false,
"data": form,
"xhr": function(){
var xhr = new XMLHttpRequest();
xhr.responseType= 'blob'
return xhr;
},
success: function(data){
console.log("Success", data);
s3.upload({
Key: "files/test.pdf",
Body: data,
ContentType: 'application/pdf',
ACL: 'public-read',
},function(err, data) {...}
},
error: function(err) {
console.log("Error", err);
}
}
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53427103%2ffile-api-works-with-curl-but-fails-with-ajax-and-postman%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
I needed to handle blob
response and thus my AJAX
call must have looked like this.
var settings = {
"async": true,
"crossDomain": true,
"url": "http://convertionapi.com",
"method": "POST",
"processData": false,
"contentType": false,
"data": form,
"xhr": function(){
var xhr = new XMLHttpRequest();
xhr.responseType= 'blob'
return xhr;
},
success: function(data){
console.log("Success", data);
s3.upload({
Key: "files/test.pdf",
Body: data,
ContentType: 'application/pdf',
ACL: 'public-read',
},function(err, data) {...}
},
error: function(err) {
console.log("Error", err);
}
}
add a comment |
I needed to handle blob
response and thus my AJAX
call must have looked like this.
var settings = {
"async": true,
"crossDomain": true,
"url": "http://convertionapi.com",
"method": "POST",
"processData": false,
"contentType": false,
"data": form,
"xhr": function(){
var xhr = new XMLHttpRequest();
xhr.responseType= 'blob'
return xhr;
},
success: function(data){
console.log("Success", data);
s3.upload({
Key: "files/test.pdf",
Body: data,
ContentType: 'application/pdf',
ACL: 'public-read',
},function(err, data) {...}
},
error: function(err) {
console.log("Error", err);
}
}
add a comment |
I needed to handle blob
response and thus my AJAX
call must have looked like this.
var settings = {
"async": true,
"crossDomain": true,
"url": "http://convertionapi.com",
"method": "POST",
"processData": false,
"contentType": false,
"data": form,
"xhr": function(){
var xhr = new XMLHttpRequest();
xhr.responseType= 'blob'
return xhr;
},
success: function(data){
console.log("Success", data);
s3.upload({
Key: "files/test.pdf",
Body: data,
ContentType: 'application/pdf',
ACL: 'public-read',
},function(err, data) {...}
},
error: function(err) {
console.log("Error", err);
}
}
I needed to handle blob
response and thus my AJAX
call must have looked like this.
var settings = {
"async": true,
"crossDomain": true,
"url": "http://convertionapi.com",
"method": "POST",
"processData": false,
"contentType": false,
"data": form,
"xhr": function(){
var xhr = new XMLHttpRequest();
xhr.responseType= 'blob'
return xhr;
},
success: function(data){
console.log("Success", data);
s3.upload({
Key: "files/test.pdf",
Body: data,
ContentType: 'application/pdf',
ACL: 'public-read',
},function(err, data) {...}
},
error: function(err) {
console.log("Error", err);
}
}
answered Nov 23 '18 at 8:13
NithinNithin
318112
318112
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53427103%2ffile-api-works-with-curl-but-fails-with-ajax-and-postman%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
What are you getting in the console.log, when you write "Success" + data?
– Brank Victoria
Nov 22 '18 at 9:06
I am getting like this imgur.com/a/hfPQdWB
– Nithin
Nov 22 '18 at 9:22
1
Then, it seems that you are getting correctly the PDF from the ajax request. Now what you need to do with that information? Download it?
– Brank Victoria
Nov 22 '18 at 9:24
I am trying to save the PDF to S3 and a PDF is being created on S3, but the entire PDF is just one empty file, by empty file i mean there is no content just plain A4 sheets :/
– Nithin
Nov 22 '18 at 9:25
I have no idea of what S3 is. Just in case, are you able to see the size of the file created in S3? Is it 51563 bytes? Or it is 0bytes?
– Brank Victoria
Nov 22 '18 at 9:27