• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

File upload in J2ME

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I need some help for my final project. I have to upload a file (audio file) to a http or ftp server from my mobile application. Can anybody help me with an advise or with an example on how to upload a file to a http/ftp server in j2me? I search a lot and I tried many things, but I don't know how to do it, that's why an example would be great.
Thank you!
 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
FTP isn't a connection type in Java ME but HTTP is.

The Package javax.microedition.io contains interfaces that you need to implement an HTTP connection, specifically cldc 1.0 has Interface HttpConnection, and if you target cldc 1.1 there's also HTTPS, s for secure, Interface HttpsConnection.

In order to implement the interfaces in the javax.microedition.io.* package, You need to use a static method call from your concrete methods to the methods in the Connector class.

If you don't know how to make a static method call, it's just [class name][dot][method name], or like:
Then, after you implement the interface, you can hook it up to the stream classes in Package java.io to help you import or export data.

You can also find an example : How to send POST data to a web server - Forum Nokia Wiki

As for the web side of the upload, you will probably need a server-side script on the website to upload things via http.
 
wand drew
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Walter for your help, but I didn't succeed yet.
Here is what I did:

recordedAudioArray contains the bytes from the file that I want to upload on http server.
Doing this, the file is not saved to my folder (htdocs) on http server. Maybe I don't understand very well, but I don't know how to do it.
 
Walter Gabrielsen Iii
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are posting to HTTP and you need to have a Servlet or other script running at the destination URL to accept the file. This would be external to your application, running on the web server. It is unlikely that you have the required web services running on your mobile device to test it locally (localhost url).
 
wand drew
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm testing on Wireless Toolkit emulators, so it should work with localhost. I hope I can do that script, even if I don't know anything about this now
 
wand drew
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Walter Gabrielsen Iii wrote:You are posting to HTTP and you need to have a Servlet or other script running at the destination URL to accept the file. This would be external to your application, running on the web server.



I searched a bit for a php script and I tried this:



The post.php code:

But it's not working. I get the message: "There was an error, try again!". Walter, can you help me please?
 
Walter Gabrielsen Iii
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That PHP script looks like it's for an upload form that goes on a web page. It's expecting more than just the file, like a file name. You will probably need to write your own customized upload script to meet your needs.

For the Server side, If you're going to use PHP then read the documentation: Handling file uploads.

For the Java ME side, There is additional help from Nokia wiki: Mobile Design Pattern: File Upload (Scroll down to the Java ME section).
 
Walter Gabrielsen Iii
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just got your PM regarding the trouble you're having with the server side script. I can't really help you with the code because it's above my head too, I not having written an upload script before.

Ok, I can tell that you aren't sending enough information to the PHP upload script that you posted last. You need to upload several things, such as a file name, See the example: HTTP Post multipart file upload with Java ME. -- be warned their PHP example only reports the file size, and doesn't save the file.



However, if you really want help you should ask someone who knows more about networking, specifically about the topic of what you need to send to the server. Perhaps, go to the Servlet section of the form, or ask at a PHP forum about what functions you need to use.
 
wand drew
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, Walter. Anyway, thanks for your help!
I tried also with that HttpMultipartRequest and with their php script, but unfortunately, it didn't report the file size or anything...
 
I'd appreciate it if you pronounced my name correctly. Pinhead, with a silent "H". Petite ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic