UTF-8 with apache commons-net - android

I have problem with Unicode, when I save file in arabic name on sdcard, all things will be good, but when file uploaded to ftp server by commons-net, I will get file name as pic
any solution please?
This is a part of code which related with FTPClient:
FTPClient ftpClient = new FTPClient();
try {
FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_NT);
conf.setServerLanguageCode("ar");
ftpClient.configure(conf);
ftpClient.setControlEncoding("UTF-8");
ftpClient.setAutodetectUTF8(true);
ftpClient.connect(server, port);
ftpClient.login(user, pass);
ftpClient.enterLocalPassiveMode();
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);

Using filenames in non-latin letters will cause a lot of problems. Many programs will not load or display such files. I would question myself, if there is really a need in this naming of files.

Related

Gmail API and size of attachment

I am using Gmail API on Android and I have a problem for file attachment.
I followed example below:
https://developers.google.com/gmail/api/guides/sending#creating_messages_with_attachments
and the problem is arisen here:
String encodedEmail = Base64.encodeBase64URLSafeString(bytes.toByteArray());
I want to attach a video file about 8MB, but this line shows 'out of memory' error.
It is okay when I send image file attachment. (Typically below 1MB).
How can I deal with it?
I don't know android, so I may be way off base, but their code shows:
mimeBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(fileDir + filename);
mimeBodyPart.setDataHandler(new DataHandler(source));
mimeBodyPart.setFileName(filename);
String contentType = Files.probeContentType(FileSystems.getDefault()
.getPath(fileDir, filename));
You are encoding the base64 directly, which explodes into a fairly large string. The FileDataSource likely works around that.

ftpclient downloaded file corrupted in android

Hi When I am trying to download a file from FTP Server in android ,The file is getting download but it is corrupted.
I have attached my code for download.
{FileOutputStream br = new FileOutputStream(DestPath);
mFTPClient
.setFileTransferMode(FTP.BINARY_FILE_TYPE);
status = mFTPClient.retrieveFile(srcFilePath,br);
}
Can anyone tell me what is the issue.
You're not using the write method. setFileTransferMode is for transfer modes. setFileType is for setting file types.
.setFileType(FTP.BINARY_FILE_TYPE);
See the docs for setFileType and setFileTransferMode.

Android commons net ftp FTPClient send small file issue

I have an issue with Apache commons-net-ftp library. What I do is send a small size MP3 files. The sizes are between 1 and 10 kb. All stages of algorithm pass well but there are NO files on FTP.
This is overview of the algorithm:
ftpClient.connect(InetAddress.getByName(mServerName));
ftpClient.login(mLogin, mPassword);
ftpClient.changeWorkingDirectory(mWorkingDir);
if (ftpClient.getReplyString().contains("250")) {
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
BufferedInputStream buffIn = new BufferedInputStream(new FileInputStream(fullPathToLocalFile));
ftpClient.enterLocalPassiveMode();
ProgressInputStream progressInput = new ProgressInputStream(buffIn, callBack);
boolean result = ftpClient.storeFile(serverFileName, progressInput);
buffIn.close();
ftpClient.logout();
ftpClient.disconnect();
}
And this is out put:
FTP Uploader
- server: ftp.***.**.**
- login: freer_********
- password: ********
FTP Uploader upload file 1367302998934.mp3 full path /mnt/sdcard/Android/data/*********.*****.********/files/mp3/1367302998934.mp3
FTP replay: 250 OK. Current directory is /htdocs/mp3
ProgressInputStream update 1024
ProgressInputStream update 2048
ProgressInputStream update 3072
ProgressInputStream update 4070
ProgressInputStream update 4070
FTP result: true
As You see, all outputs are point to normal behavior but the is NO file on FTP server.
Does anyone has experience with same problem ?
Sorry guys for the post, the answer was very clear ...
The host provider I used has a service to monitor "mp3" content. It not allow to use mp3 files to store on the host.
P.S. I wish to close this post but I don't know how.

Upload file to FTP

I'm trying to upload a file to an FTP using apache commons ftp.
I am using a code that I have seen on several websites, including stackoverflow
Android FTP Library
The problem is that in the line:
Buffin = new BufferedInputStream (new FileInputStream (file));
I can not put any paths in "file", eclipse does not validate any values ​​or path-
What would have to indicate in "new FileInputStream"?
I do not know I'm doing wrong.
Thank you very much and best regards
You need a File object to pass it to the FileInputStream.
Buffin = new BufferedInputStream(new FileInputStream(new File("/path/to/file"));
And you can't Upload file to FTP because FTP is not a place, it is a protocol.
Create a File object with the path and pass it in.
You can do this:
Buffin = new BufferedInputStream (new FileInputStream (<path to your file>));
Details here:
FileInputStream

Read local compressed XML file(gzip) in Android application

I don't know how to get an InputStream(Read gzipped local xml file) from the locally stored gzip xml file.
employee.gz
If someone Can help I really appreciate. Thanks
This link works with zip. http://techdroid.kbeanie.com/2010/10/unzip-files-in-android.html
I am not sure if it will work with gz files, but you could give it a try. There's a documentation on GZIPInputStream class on the dev docs.
http://developer.android.com/reference/java/util/zip/GZIPInputStream.html
This piece of code works.
GZIPInputStream inputStream = new GZIPInputStream(new FileInputStream(new File(
"path to file")));
String str = IOUtils.convertStreamToString(inputStream);
I have used a util class which converts the input stream to a string. You might want to do the reading part manually.

Categories

Resources