Discuss Integral FTP, our Javascript secure FTP client.
no avatar
User

Lapsus

Posts

4

Joined

Wed Apr 03, 2013 7:33 pm

Sending binary via uploadText

by Lapsus » Wed Apr 03, 2013 7:47 pm

Hi,

and thanks in advance for any help.
I am trying to send a binary file via the uploadText() function.
Why? Good question. I fetch a file (jpg) with an ajax request and want to send it with IntegralFTP.
Therefore i have a string with the binary data of the image. The ajax response has the image data base64 encoded to ensure proper transfer.
If i send the data base64 encoded it works correctly but the image is (of course) corrupt because it is not decoded at the recieving end.
If i send it decoded the upload stops after a few bytes.

I tried to set TransferType (binary), ConnectMode (passive) and CharacterSet (UTF-8) manually to ensure the correct settings for sending the data but with no effect.
Are the parameters for uploadText hardcoded?
Is there another way to send da binary string?

Any help appreciated.
no avatar
User

EDT Support

Posts

905

Joined

Mon Apr 26, 2004 3:03 pm

Re: Sending binary via uploadText

by EDT Support » Thu Apr 04, 2013 9:37 am

There's currently no way to do it, but we can add an uploadBytes method for you. What's the data-type of the data that you want to upload?

- Hans (EnterpriseDT)
Last edited by EDT Support on Mon Apr 08, 2013 11:13 pm, edited 1 time in total.
no avatar
User

Lapsus

Posts

4

Joined

Wed Apr 03, 2013 7:33 pm

by Lapsus » Mon Apr 08, 2013 3:48 am

Hi,

Sorry for the late answer, i was traveling and not in reach of a computer.
I want to upload an image (jpg) which i fetched via ajax.

and thanx for the quick reply.
no avatar
User

EDT Support

Posts

905

Joined

Mon Apr 26, 2004 3:03 pm

by EDT Support » Mon Apr 08, 2013 11:15 pm

OK, yes, I understood that, but as I understand it you're going to want to pass a Javascript variable that references the image-data to the uploadBytes method, right? My question is, what will the data-type of that variable be? Have you perhaps got some sample code that will show how it will be used?

- Hans (EnterpriseDT)
no avatar
User

Lapsus

Posts

4

Joined

Wed Apr 03, 2013 7:33 pm

by Lapsus » Tue Apr 09, 2013 5:54 pm

Thanx agin for your help.

The variable is a string. Example Code looks like this:
I basically used the SubmitFormToFtp example and called submit() via a http link instead of a submit button.

Code: Select all
// Called when a connection has been made (or failed)
function onConnect(status)
{
    if (status.success)
    {
        setStatus("Uploading image");
        var image = $('#uploadImg_' + imageId);
        var imgUrl = image.attr('src') + '/format/json';
        //onImageFetch calls ftp.uploadText(imagedata, imagefilename)
        $.get(imgUrl, '', onImageFetch);
        //ftp.uploadText(submissionText, serverFileText.value
        // onUploadText will be called when the text has been upload
    }
    else
    {
        setStatus("Could not connect.");
    }
}

function onImageFetch(data, textStatus)
{
    ftp.setTransferType('binary');
    ftp.setConnectMode('passive');
    ftp.setCharacterSet('UTF-8');
   
    ftp.uploadText(base64_decode(data.file), data.filename);
}


The rest is the same code as in the example. I hope that helps you understand my problem and find a work around.
$.get(imgUrl, '', onImageFetch); uses JQuery for the ajax call. and ftp.uploadText(base64_decode(data.file), data.filename); uses another javascript function to decode the string.

Regards
no avatar
User

EDT Support

Posts

905

Joined

Mon Apr 26, 2004 3:03 pm

by EDT Support » Tue Apr 09, 2013 7:32 pm

Are you sure the data-type is string? This seems a strange data-type for an image.

If you e-mail me at support@enterprisedt.com I can send you an experimental version with the new uploadBytes method. The Java applet method that's called takes a byte-array as an argument, so the question is whether the Javascript-Java adapter can do the conversion or not.

- Hans (EnterpriseDT)
no avatar
User

Lapsus

Posts

4

Joined

Wed Apr 03, 2013 7:33 pm

by Lapsus » Tue Apr 09, 2013 9:04 pm

Hi,

as requested i sent you an email. Im quite sure it is a string. But i will double check that.
And if the conversion is not done correctly i think it should be possible for me to convert the data to a byte array before calling uploadBytes() with something like the following
Code: Select all
var str = "Hello";
var bytes = [];

for (var i = 0; i < str.length; ++i)
{
    bytes.push(str.charCodeAt(i));
}
no avatar
User

EDT Support

Posts

905

Joined

Mon Apr 26, 2004 3:03 pm

by EDT Support » Wed Apr 10, 2013 12:25 am

Note to readers: Conversation taken offline.
no avatar
User

support2

Posts

3987

Joined

Tue May 18, 2004 8:30 am

by support2 » Sat Jan 25, 2014 10:51 pm

Please see this post

Who is online

Users browsing this forum: No registered users and 1 guest

Powered by phpBB ® | phpBB3 Style by KomiDesign
cron