Bryan Novak
Posts: 0
Joined: Thu May 01, 2014 4:29 pm

Internal Server Error during PDF upload

Hi again,

The project I've mentioned in two other posts continues. I've changed it a bit so that instead of generating a PDF in the app and then attaching it to a Sendgrid email (which I never got working) I've opted instead to generate the PDF file, upload it to the files DB and then post a link of it in the email.

So far I've gotten this to work using a file input interface within the Appery web environment, but since I can't force the PDF I'm generating into the that dom element, I'm trying to pass it along to the service using javascript. When I do this however, I get an Internal Server Error in the jqXHR response text (seen below)

{"code":"DBFM000", "description":"This wasn't supposed to happen but an error occurred. Please try again. If the error persists please let us know on the http://appery.io/forum or email us: a href="mailto:support@appery.io" rel="nofollow"support@appery.io/a"}

Here's the call that gives me the error

uploadMultipleFilesHelper(email_file_upload, pdfPath1);

Where "email_file_upload" is the name of the service set up by using the Upload File tutorial (http://docs.appery.io/tutorials/uploa...) and "pdfPath1" is the PDF converted to binary seen below:

"data:application/pdf; base64,JVBerUHFDJhdjk...and so on"

It still isn't clear to me if the way I'm sending the file along is correct (does it need to be put in a Blob or something?) but the base64 is the only time the app takes a second to try and process the task before throwing the error. Any idea what might be causing this error, or is there a better way of uploading the file to the server?

Thanks

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Internal Server Error during PDF upload

HI Bryan,

What is the type of the field where you are saving base64 string?
Please post screenshots of service mapping and service settings.

Bryan Novak
Posts: 0
Joined: Thu May 01, 2014 4:29 pm

Internal Server Error during PDF upload

I'm saving the base64 string in a simple javascript var and then passing it into the upload helper described in the upload tutorial. In the tutorial the input file dom element is what is normally passed in. Is there a way I can replicate the format the helper method needs?

Image

Image

Bryan Novak
Posts: 0
Joined: Thu May 01, 2014 4:29 pm

Internal Server Error during PDF upload

Also, here's the code that converts the file to the base64:

function readDataUrl(file) {
var reader = new FileReader();
reader.onloadend = function(evt) {
console.log("Read as data URL");
console.log(evt.target.result);
pdfPath1 = evt.target.result;
uploadMultipleFilesHelper(email_file_upload, pdfPath1);
};
reader.readAsDataURL(file);

Bryan Novak
Posts: 0
Joined: Thu May 01, 2014 4:29 pm

Internal Server Error during PDF upload

Thanks for the quick response. I made a reply below. I wasn't sure if you receive a notification since I did it that way, so I just wanted to be sure.

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Internal Server Error during PDF upload

Hello Bryan,

You can't use function uploadMultipleFilesHelper when you don't use Input component with type "file"(can't pass to this function just binary data).
You can save your pdf file in any string in custom collections. Please look through our tutorial: http://docs.appery.io/tutorials/using...

Bryan Novak
Posts: 0
Joined: Thu May 01, 2014 4:29 pm

Internal Server Error during PDF upload

If I store it as a string, is there a way I can link to it outside of Appery? My users need to be able to download and print the document so is there a way I could just link to the file and have it render in a browser window?

Note: I've tried sending the base64 string through Sendgrid's email service and it strips out the whole url (or Outlook strips it, I'm not quite sure).

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Internal Server Error during PDF upload

Hello Brian,

You can upload any data to files collection with javascriptcode. This discussion can help you: https://getsatisfaction.com/apperyio/...
First try to upload any simple text to files collection. Your can have such javascript code:

codevar serverUrl = 'https://api.appery.io/rest/1/db/files/q.txt';

$.ajax({
type: "POST",
beforeSend: function(request) {
request.setRequestHeader("X-Appery-Database-Id", '1111');
request.setRequestHeader("X-Appery-Session-Token", '1111111111);
request.setRequestHeader("Content-Type", 'text/plain');
},
url: serverUrl,
data: "as",
processData: false,
contentType: false,
success: function(data) {
alert("success");
},
error: function(data) {
alert("error");
}
}); /code

Jack Bua
Posts: 0
Joined: Sun Jun 28, 2015 10:16 pm

Internal Server Error during PDF upload

Hello Evgene,

If you don't mind, do you think you can continue with me where you left off with Brian please?

I have successfully tested this simple file POST using my DB ID and Token grabbed from login via LSV.

My goal is to use jsPDF to make a file then to save it directly to the File Collection, and to somehow place a pointer or link to the created PDF it in a record in another collection so when that record is pulled up, a single button click can save the pdf to the device or attach it to an email

Could you please help me:

1) save the created PDF directly to the DB
2) obtain identifying info (url, ID)*

*to use to apply to another collection's record for purpose of saving/email upon user click of button. (you dont need to assist me with the saving/emailing, just the obtaining portion.)

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Internal Server Error during PDF upload

Hello Jack,

Please read this tutorial about uploading files: https://devcenter.appery.io/tutorials...

Return to “Issues”