-1

私はBlackberry開発の初心者であり、デバイスギャラリーからサーバーに画像をアップロードする必要があります。この点に関連するリンクをたくさん見つけました。しかし、私はこの問題の正確な結果を見つけることができません。このを使用しました。この例を使用して、値をByte []に​​取得しましたが、このコードを使用して要件を満たすことができません。その点で、コードでどのURLを渡す必要があり、どのURLがパラメーターであるかがわかりません。

もう1つの形式を使用しました。ここにコードを投稿し、これを使用して応答コード:200を取得しました。しかし、私はこれを解決することはできません

HttpConnection oCon = (HttpConnection)Connector.open("http://74.208.77.106/jm/testing/iDaddyapi.php;deviceside=true;interface=wifi");
                 oCon.setRequestMethod(HttpConnection.POST);
                 oCon.setRequestProperty("Content-Length", "" + imageByte.length);

                 URLEncodedPostData oPostData = new URLEncodedPostData(URLEncodedPostData.DEFAULT_CHARSET, false);

                 oPostData.append("api", "postidaddyimage");
                 oPostData.append("imagetype", "F");
                 oPostData.append("image", strImage);

                 OutputStream strmOut = oCon.openOutputStream();
                 strmOut.write(oPostData.getBytes());

                 strmOut.flush();
                 strmOut.close();



     int rc = oCon.getResponseCode();
     System.out.println("Response code.............."+rc);
     if (rc != HttpConnection.HTTP_OK)
                     throw new IOException("Error response code: " + rc);

誰か助けてもらえますか?私はこれで立ち往生しています。

ありがとう、マンシ

4

2 に答える 2

0
HttpConnection conn = (HttpConnection) Connector.open(Url, Connector.READ_WRITE);

conn.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_LENGTH,
            String.valueOf(imagedata.length));

conn.setRequestProperty("x-rim-transcode-content", "none");
ByteArrayOutputStream out = new ByteArrayOutputStream();
OutputStream finalOut = conn.openOutputStream();

String newLine = "\r\n";
out.write(newLine.getBytes());
out.write("--".getBytes());
out.write(boundary.getBytes());
out.write(newLine.getBytes());
String contDisp = "Content-Disposition:form-data;  
name=\"file\";filename=\"Image.jpg\"";
String contEnc = "Content-Transfer-Encoding: binary";
String type = "Content-Type:image/jpeg";
out.write(contDisp.getBytes());
out.write(newLine.getBytes());
out.write(type.getBytes());
out.write(newLine.getBytes());
out.write(contEnc.getBytes());
out.write(newLine.getBytes());
out.write(newLine.getBytes());
out.write(imagedata);
out.write(newLine.getBytes());
out.write("--".getBytes());
out.write(boundary.getBytes());
out.write("--".getBytes());
out.write(newLine.getBytes());
finalOut.write(out.toByteArray());

out.flush();
out.close();

finalOut.flush();
finalOut.close();
于 2011-10-17T13:11:14.443 に答える
0
    public class ImageUploader extends Thread {

String filename;
Bitmap temp;
public ImageUploader(String filename)
{
    this.filename=filename;
}
public void run() {
    final String boundary = "Some_Unique_Text_Also_Alphanumeric";   

    try
    {
        //FileInputStream fis=new FileInputStream(File.FILESYSTEM_PATRIOT,filename);
        FileConnection fis=(FileConnection)Connector.open(filename);
        InputStream inputStream = fis.openInputStream();
        ByteArrayOutputStream bos=new ByteArrayOutputStream();
        int buffersize=1024;
        byte[] buffer=new byte[buffersize];
        int length=0;
        while((length=inputStream.read(buffer))!=-1)
        {
            bos.write(buffer,0,length);
        }
        byte[] imagedata=bos.toByteArray();

        HttpConnection conn = (HttpConnection) Connector.open(URL, Connector.READ_WRITE);
        conn.setRequestMethod(HttpConnection.POST);

        conn.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_TYPE,
                HttpProtocolConstants.CONTENT_TYPE_MULTIPART_FORM_DATA
                        + ";boundary=" + boundary);
        conn.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_LENGTH,
                String.valueOf(imagedata.length));
        conn.setRequestProperty("x-rim-transcode-content", "none");

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        OutputStream finalOut = conn.openOutputStream();

        String newLine = "\r\n";
        out.write(newLine.getBytes());
        out.write("--".getBytes());
        out.write(boundary.getBytes());
        out.write(newLine.getBytes());
        String contDisp = "Content-Disposition:form-data; name=\"file\";filename=\"Image.jpg\"";
        String contEnc = "Content-Transfer-Encoding: binary";
        String type = "Content-Type:image/jpeg";
        out.write(contDisp.getBytes());
        out.write(newLine.getBytes());
        out.write(type.getBytes());
        out.write(newLine.getBytes());
        out.write(contEnc.getBytes());
        out.write(newLine.getBytes());
        out.write(newLine.getBytes());
        out.write(imagedata);
        out.write(newLine.getBytes());
        out.write("--".getBytes());
        out.write(boundary.getBytes());
        out.write("--".getBytes());
        out.write(newLine.getBytes());
        finalOut.write(out.toByteArray());

        out.flush();
        out.close();

        finalOut.flush();
        finalOut.close();
        InputStream instream=conn.openInputStream();
        int ch=0;
        StringBuffer buffesr=new StringBuffer();
        while((ch=instream.read())!=-1)
        {
            buffesr.append((char)ch);
        }

        JSONObject myprofileObject = new JSONObject(buffesr.toString());
        String result = myprofileObject.optString("result");
        String url = myprofileObject.optString("url");
        String message=myprofileObject.optString("msg");
        MyProfile._model.setProfilePic(url);

    }
    catch (Exception e) {
        // TODO: handle exception
    }
};
    thread.start(); 
}
}
于 2011-10-18T08:44:26.633 に答える