Android的:简单的方式将图片上传到主机的图像 [英] Android: Simple way to upload a picture to an image host

查看:117
本文介绍了Android的:简单的方式将图片上传到主机的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我倒要的图片上传到像一个主持人: http://imagerz.com/
任何样本吗?我可以做一个简单的POST请求,但我怎么能图像内容添加到我的POST请求?

I d like to upload a picture to a host like: http://imagerz.com/ . Any sample for this? I can do a simple POST request, but how I can add the image content to my POST request?

推荐答案

下面是告诉你如何通过FTP 发送的文件到服务器的教程。 文件上传和下载使用Java

Here is a tutorial that tells you how to send a file via FTP to a server. File upload and download using Java

它不应该是很困难的端口即code到机器人。 (您可能需要改变一些类/方法为其中一些可能无法在Android的轻量级虚拟机来实现)。

It shouldn't be very hard to "port" that code into android. (You may have to change some of the classes/methods as some of them may not be implemented in Android's lightweight VM).

有也应该有,你可以遵循API其他图片托管服务。

There are also other image hosting services that should have an api that you could follow.

编辑:

正如你所说,你想用POST请求来做到这一点。

As you stated, you wanted to do this with a post request.

我发现这个伟大的教程,下面code:

I found this great tutorial with the following code:

package com.commonsbook.chap9;
import java.io.File;
import java.io.IOException;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.MultipartPostMethod;

public class HttpMultiPartFileUpload {
    private static String url =
      "http://localhost:8080/HttpServerSideApp/ProcessFileUpload.jsp";

    public static void main(String[] args) throws IOException {
        HttpClient client = new HttpClient();
        MultipartPostMethod mPost = new MultipartPostMethod(url);
        client.setConnectionTimeout(8000);

        // Send any XML file as the body of the POST request
        File f1 = new File("students.xml");
        File f2 = new File("academy.xml");
        File f3 = new File("academyRules.xml");

        System.out.println("File1 Length = " + f1.length());
        System.out.println("File2 Length = " + f2.length());
        System.out.println("File3 Length = " + f3.length());

        mPost.addParameter(f1.getName(), f1);
        mPost.addParameter(f2.getName(), f2);
        mPost.addParameter(f3.getName(), f3);

        int statusCode1 = client.executeMethod(mPost);

        System.out.println("statusLine>>>" + mPost.getStatusLine());
        mPost.releaseConnection();
    }
}

来源: http://www.theserverside.com/news/1365153/ HttpClient的-和文件上传

有关这种移植code,以Android作为我上面说的适用同样的问题。

The same issues about porting this code to android as I stated above apply.

这篇关于Android的:简单的方式将图片上传到主机的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆