zrrrzzt / docker-unoconv-webservice

Dockerfile to run unoconv as a webservice
MIT License
96 stars 35 forks source link

Browser based calls are creating blank PDFs #19

Closed nithinkashyapn closed 5 years ago

nithinkashyapn commented 5 years ago

Hey,

Thanks for the wonderful docker image.

I am trying to implement unoconv API from the browser using AJAX and it's resulting in PDFs being created from documents with no content inside them.

My regular AJAX call looks like this

var files = document.getElementById('filespace').files;
if (!files.length) {
    return alert('Please choose a file to upload first.');
}
var file = files[0];

var form = new FormData();
form.append("file", file);

var settings = {
    "async": true,
    "crossDomain": true,
    "url": "http://unoconvexample.com/unoconv/pdf",
    "method": "POST",
    "processData": false,
    "contentType": false,
    "data": form
}

$.ajax(settings)
    .done(function (response) {
        console.log("Response", response);
        doSomething(response);
    });

This is creating a bin file on Postman and an empty PDF when i save to storage. It is working with cURL.

Is there any other step which needs to be done while implementing on browser?

zrrrzzt commented 5 years ago

I've actually never tried to use this from the browser myself. The way I usually call the service is from other servers or services. I do see the usefulness in being able to call it from a browser so if you have a repo with a form example I could use for testing I can look into it.

nithinkashyapn commented 5 years ago

Hey,

Will create and send the link within few minutes. Simple AJAX would do right?

zrrrzzt commented 5 years ago

Yes. Keep it minimal :-)

nithinkashyapn commented 5 years ago

Hey,

I've implemented the browser based API here

https://github.com/nithinkashyapn/browser-file-convert

Thanks.

nithinkashyapn commented 5 years ago

Hey,

I seem to have got it to start working. All i needed was to handle the blob type. I checked the same via XMLHttpRequest() and AJAX. It works.

I've updated the repository as well.

Thanks.

zrrrzzt commented 5 years ago

Cool. Will you keep the repo public so I can reference it from the README?

nithinkashyapn commented 5 years ago

Yep,

The repository would remain public. It'll be a privilege to be referenced.

Thank you

zrrrzzt commented 5 years ago

Finally got the time to do an update so you are now a part of the README :-)

If everything is okay feel free to close the issue.

nithinkashyapn commented 5 years ago

Thank you very much.

Will close the issue.

Take care.