Yes, indeed his approach is much cumbersome.

For uploading files to a server Multipart is a great class featured in
apache commons (it comes with Android), which will leave you away of
coding your output at a very low level.

http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/methods/multipart/package-summary.html

However, some times servers can be very picky, specially if you are
not in control of them and using external services like Picasa or
Flickr. You may end up stumbling with most of the http status error
codes, many of them you have never seen. In those cases, when you need
to taylor a very specific structure, Multipart may not suit for you,
so you would need something that gives you more control of your http
connection, like HttpURLConnection (also featured in http commons)

The example you mentioned uses this second approach, by writing ouput
to a stream (conn.getOutputStream(), write ouput, and the
conn.connect() to send the request)

In any case, dont be afraid, as long as you can control a http
connection you can do whatever.

br,

On Apr 16, 9:17 pm, "Dan U." <[EMAIL PROTECTED]> wrote:
> Well, it looks to me like the author re-invented the wheel. It's quite
> easy to post an image to a server. Here's some code in one of my
> applications that has been modified to be more generic. I didn't test
> the modifications, but it should work. Note that I'm posting both the
> file (videoFile) and a text description of it (videoName)
>
>                 String response = null;
>                 String TAG = "ERROR";
>                 PostMethod method;
>                 try {
>                         HttpClient client = new HttpClient();
>                         
> client.getHttpConnectionManager().getParams().setConnectionTimeout(
>                                         5000);
>                         method = new PostMethod(urlString);
>
>                         Part[] parts = {
>                                         new FilePart("videoFile", new 
> ByteArrayPartSource(
>                                                         "videoFile", data)),
>                                         new StringPart("videoName", filename) 
> };
>                         method.setRequestEntity(new 
> MultipartRequestEntity(parts, method
>                                         .getParams()));
>                         client.executeMethod(method);
>                         response = method.getResponseBodyAsString();
>                         method.releaseConnection();
>                 } catch (Exception ex) {
>                         Log.v(TAG, "Exception", ex);
>                 } finally {
>                         method.releaseConnection();
>                 }
>                 return response;
>
> On Apr 16, 10:26 am, "Bryan.paul" <[EMAIL PROTECTED]> wrote:
>
> > I posted this in beginners and got no response, but it appears this
> > group is far more active; I hope this doesn't offend anyone.
>
> > I have been reading a lot of documentation, and I'm looking to start
> > building my application very soon. However, I'm not sure how I want to
> > handle a key aspect of it, and I want to get it straightened out
> > before I get too far in the development process:
>
> > I want users to be able to upload a file from their handset to my
> > webpage. I have a shared hosting plan (at least now), and I'm mainly
> > working in PHP and MySQL serverside. What would be the best way to
> > handle this transaction? I'm flexible and I'm open to any options.
> > I have very limited experience with file transfers, and I'm not sure
> > how to best jump this hurdle. I'd like to not have to rely on them
> > using the browser and a form, but keep the entire upload within the
> > application itself on Android. But then I'm not sure how I would set
> > this up with my website.
>
> > I did find this 
> > here:http://getablogger.blogspot.com/2008/01/android-how-to-post-file-to-p...
> > It shows both the webserver and android end to uploading a file. Any
> > other input is still appreciated, although this may be what I
> > was looking for. So I know it's possible, just need to dissect the
> > code and make sure this is the most efficient and best way to do
> > this.
>
> > Any and all feedback is appreciated, and even
> > something to suggest for me to research on my own would be great.
> > Thanks in advance for your time and consideration.
>
> > Bryan
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to