Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从android上传多部分文件_Android_Multipartentity - Fatal编程技术网

从android上传多部分文件

从android上传多部分文件,android,multipartentity,Android,Multipartentity,我正在发送一个多部分请求,我的文件如下所示 entity.addPart(entry.getValue().getName(), new FileBody(entry.getValue(), entry.getValue().getName(), "image/jpeg", "ISO-8859-1")); 实体是一个MultipartEntityBuilder对象 我还想设置内容配置。如何设置文件的内容配置?请帮助尝试以下操作:- InputStream inputStream = n

我正在发送一个多部分请求,我的文件如下所示

    entity.addPart(entry.getValue().getName(), new FileBody(entry.getValue(), entry.getValue().getName(), "image/jpeg", "ISO-8859-1"));
实体是一个MultipartEntityBuilder对象

我还想设置内容配置。如何设置文件的内容配置?请帮助尝试以下操作:-

InputStream inputStream = new FileInputStream(new File(String.valueOf(params[0])));

//*** CONVERT INPUTSTREAM TO BYTE ARRAY
byte[] data = this.convertToByteArray(inputStream);

            HttpClient httpClient = new DefaultHttpClient();


HttpPost httpPost = new HttpPost(UPLOAD_SERVER_URI);

String boundary = "----WebKitFormBoundarypJjqFVXFVatNaatW";

httpPost.setHeader("Accept", "*/*");
httpPost.setHeader("Content-type", "multipart/form-data; boundary="+boundary);

//File Data
InputStreamBody inputStreamBody = new InputStreamBody(new ByteArrayInputStream(data), "image/jpeg");

    CustomMultiPartEntity multipartEntity = new CustomMultiPartEntity();

            // SET UPLOAD LISTENER
            multipartEntity.setUploadProgressListener(this);

            //*** ADD THE FILE
            multipartEntity.addPart("imagecode", inputStreamBody);

            /** Add String Data */
            entity.addPart("companycode", new StringBody(companycode));

            httpPost.setEntity(multipartEntity);

            // EXECUTE HTTPPOST
            HttpResponse httpResponse = httpClient.execute(httpPost);

            // THE RESPONSE FROM SERVER
            String stringResponse = EntityUtils.toString(httpResponse.getEntity());

            // DISPLAY RESPONSE OF THE SERVER
            Log.d("data from server", stringResponse);

我的问题是关于设置内容配置,例如:-内容配置:表单数据;名称=附件3;filename=file.jpgI我在volley中使用的是请求类,而不是基本的HttpClient。如果我们使用volley,则有一个名为FormBodyPart的类,它将设置内容类型和内容处置。我的错误是我没有提供完整的文件名,只是指定了没有扩展名的文件名。@RajiAC表示您找到了解决方案。