I need to upload files to the Parashift API.
In the docs( https://docs.parashift.io/extraction-ap ... ument.html ) I read that it's possible to send the file as Base64 encoded arrays.
.... As an alternative to a list of URLs, files can be delivered as an array of base64 encoded strings...
I have no clue how to make this happen... Can I read the File in with Base64 encoding? Like this: "File.read( job.getPath(), "Base64" );"
With the Code below I am getting Status Code 400... bad requests. I guess my code is complete garbage.
Code: Select all
function jobArrived( s : Switch, job : Job )
{
var pdf = File.read( job.getPath(), "Base64" );
var url = "https://extraction.api.parashift.io/v1/666/documents/";
var token = "asdasdadsadsadsadsadsadsadsadsasdasdsasdasdasdasdasdasdad";
var filename = job.getName();
var theHTTP = new HTTP( HTTP.SSL );
theHTTP.authScheme = HTTP.OauthAuth;
theHTTP.authorization = "Bearer "+token;
theHTTP.url = url;
var Body = pdf;
var postBody = new ByteArray(Body);
theHTTP.setPostData( postBody,"application/vnd.api+json" );
theHTTP.post();
while( !theHTTP.waitForFinished( 3 ) )
{
job.log( 1, "API CALL IN PROGRESS!" );
}
if( theHTTP.finishedStatus == HTTP.Ok && theHTTP.statusCode == 200 )
{
job.log(1,"API CALL successfull Code: "+theHTTP.statusCode +", RESPONSE: "+theHTTP.getServerResponse().toString( "UTF-8" ));
}
else
{
job.log(3,"API CALL Failed: "+theHTTP.getServerResponse().toString( "UTF-8" )+ " Status Code: "+theHTTP.statusCode.toString( "UTF-8" ));
}
}