Hi,
I use the Attachment API to upload files to a LiquidFiles server. This so far works fine. For big files, however, I run into memory issues with my current implementation, which is why I wanted to change the upload process, to upload the file in chunks. Doing so, however, resulted in broken files being uploaded, where the problem lies, I believe, in the wrong charset being used.
Correct:
Broken:
My question now is, whether this could be an error on the LiquidFiles side. I use a perl script, which uses HTTP::Request::Common to do all the file processing, I don't do much at all. If I rebuild the content of the request and just write it to a file, everything is intact. I will provide a minimal example to upload files. Changing the variable $DYNAMIC_FILE_UPLOAD toggles the chunking. All suggestions are appreciated.
I use the Attachment API to upload files to a LiquidFiles server. This so far works fine. For big files, however, I run into memory issues with my current implementation, which is why I wanted to change the upload process, to upload the file in chunks. Doing so, however, resulted in broken files being uploaded, where the problem lies, I believe, in the wrong charset being used.
Correct:
Code:
%PDF-1.5
%ÐÔÅØ
90 0 obj
[...]
Broken:
Code:
%PDF-1.5
%Ã<90>Ã<94>Ã<85>Ã<98>
90 0 obj
[...]
My question now is, whether this could be an error on the LiquidFiles side. I use a perl script, which uses HTTP::Request::Common to do all the file processing, I don't do much at all. If I rebuild the content of the request and just write it to a file, everything is intact. I will provide a minimal example to upload files. Changing the variable $DYNAMIC_FILE_UPLOAD toggles the chunking. All suggestions are appreciated.
Code:
#!/usr/bin/perl -w
use strict;
use LWP::UserAgent qw( );
use HTTP::Request::Common qw($DYNAMIC_FILE_UPLOAD);
use MIME::Base64;
# Here the chunking can be enabled, which breaks certain files
$DYNAMIC_FILE_UPLOAD = 1;
# Provide Data
my $APIKey = 'API Key';
my $LiquidFileServer = 'https://my.lfserver.com';
my $File = '/path/to/file.ext';
my $KeyEncoded = encode_base64( "$APIKey:x\n" );
my $LFAuth = "Basic $KeyEncoded";
my $ua = LWP::UserAgent->new();
$ua->ssl_opts(verify_hostname => 0);
$ua->default_header( Authorization => $LFAuth );
# Upload File
my $request = HTTP::Request::Common::POST(
"$LiquidFileServer/attachments",
Content_Type => 'form-data',
Content => [
Filedata => [ $File ],
],
);
my $response = $ua->request($request);
my $AttachmentID = $response->content;
# Get URL
$response = $ua->post(
"$LiquidFileServer/message",
Content_Type => 'application/json',
Content =>
'{"message":
{
"recipients":["foo@bar.com"],
"subject":"test subject",
"message":"Please let me know what you think!",
"send_email":false,
"authorization":0,
"attachments":["'.$AttachmentID.'"]
}
}'
);
$response->content =~ /url":"(.+)"/;
print "DownloadURL: $1\n";
Last edited: