Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
7.5k views
by (240 points)
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.

8 Answers

0 votes
by (51.6k points)
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)
0 votes
by (240 points)
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.
0 votes
by (51.6k points)
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)
0 votes
by (240 points)
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.

// 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
0 votes
by (51.6k points)
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)
0 votes
by (240 points)
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
var str = "Hello";
var bytes = [];

for (var i = 0; i < str.length; ++i)
{
    bytes.push(str.charCodeAt(i));
}
0 votes
by (51.6k points)
Note to readers: Conversation taken offline.
0 votes
by (162k points)
Please see this post

Categories

...