gpt4 book ai didi

file - 改造分段上传图片失败

转载 作者:行者123 更新时间:2023-12-04 13:49:31 24 4
gpt4 key购买 nike

我正在尝试使用翻新库上传图像。这就是我上传的方式:

请求代码:

@Multipart
@POST("/customerapp/{context}/{token}/passenger/passport/add/{passengerId}")
@Headers({
"Accept: application/xml",
"Accept-Encoding: gzip"
})
void UploadImage(
@Path("context") String context,
@Path("token") String token,
@Path("passengerId") String passengerId,
@Query("fileType") String fileType,
@Query("imageCategory") int imageCategory,
@Part("imageContent") TypedFile file,
Callback<VJSuccessResponse> callback
);



public static final String BASE_URL =
"http://webservicetest.abc.com/extranetServices/1.1";

RequestInterceptor requestInterceptor = new RequestInterceptor() {
@Override
public void intercept(RequestFacade request) {
Log.e("Retrofit Request Body", request.toString());
}
};

RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint(BackendConstants.BASE_URL)
.setClient(new OkClient(new OkHttpClient()))
.setConverter(new SimpleXMLConverter())
.setLogLevel(RestAdapter.LogLevel.FULL)
.setRequestInterceptor(requestInterceptor)
.build();

REST_CLIENT = restAdapter.create(BackendAPI.class);

REST_CLIENT.UploadImage(
BackendConstants.CONTEXT,
StateObject.sSPManager.getStoredPersonalDetails().getToken(),
passengerId,
new File(filePath),
imageCategory,
new TypedFile("image/jpeg", typeFile), new Callback<VJSuccessResponse>() {
@Override
public void success(VJSuccessResponse getCallResponse, Response response) {

}

@Override
public void failure(RetrofitError error) {


Log.d(TAG, error.toString());
}
})

回复:
HTTP POST http://webservicetest.abc.com/extranetServices/1.1/customerapp/customerapp/cba75eb0d5d64e16b37cca477d68d836/passenger/passport/add/56672?fileType=jpg&imageCategory=1
Accept: application/xml
Accept-Encoding: gzip
Content-Type: multipart/form-data; boundary=fb1f78df-d674-4e54-9b41-32a386ca4222
Content-Length: 6038770
Content-Disposition: form-data; name="imageContent"; filename="userdp.jpg"
Content-Type: image/jpeg
Content-Length: 6038513

Content-Transfer-Encoding: binary
������JFIF����������������C������C�����,"��������������������������
�����������}��!1AQa"q2���#B��R��$3br�
(That goes long String of garbage...)


<--- HTTP 200 http://webservicetest.abc.com/extranetServices/1.1/customerapp/customerapp/cba75eb0d5d64e16b37cca477d68d836/passenger/passport/add/56672?fileType=jpg&imageCategory=1 (109092ms)
Date: Thu, 05 Feb 2015 14:52:28 GMTServer: GlassFish Server Open Source Edition 3.1.2.2
X-Powered-By: Servlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.1.2.2 Java/Sun Microsystems Inc./1.6)
Content-Encoding: gzip
Content-Type: application/xml
Content-Length: 108
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
OkHttp-Selected-Protocol: http/1.1
OkHttp-Sent-Millis: 1423148584220
OkHttp-Received-Millis: 1423148693098
��������������������Q(K-*��ϳU2�3PRH�K�O��K�U
qӵPR(.I�KI���K�U�L-V���)�
J-.��+N��).MNN-.�+)*M�ч�l�������u��g������
<--- END HTTP (108-byte body)
retrofit.RetrofitError: org.xmlpull.v1.XmlPullParserException: Unexpected token (position:TEXT �������������������Q...@3:38 in java.io.InputStreamReader@26e1231a)

如果我通过诸如 postman 或DHC之类的客户端浏览器进行发布,则该请求与上面的请求相同,并且我收到了成功的XML响应。

请查看我尝试使用 postman 客户端时的屏幕截图。成功了。

最佳答案

我也遇到了类似的问题,经过几个小时的尝试,我终于将图像上传功能构建到了远程服务器上。
要上传图片,您需要正确创建API,还需要正确传递图片。在Retrofit客户端中,您需要按照以下步骤设置镜像:

String photoName = "20150219_222813.jpg";
File photo = new File(photoName );
TypedFile typedImage = new TypedFile("application/octet-stream", photo);

RetrofitClient.uploadImage(typedImage, new retrofit.Callback<Photo>() {

@Override
public void success(Photo photo, Response response) {
Log.d("SUCCESS ", "SUCCESS RETURN " + response);
}

@Override
public void failure(RetrofitError error) {

}
});

API设定:

@Multipart
@POST("/")
void uploadImage(@Part("file") TypedFile file, Callback<Photo> callback);

远程服务器端PHP代码来处理图像:

$pic = 'uploaded_images/' . $imagename . '.jpg';
if (!move_uploaded_file($_FILES['file']['tmp_name'], $pic)) {
echo "posted";
}

如果可以帮助任何人,请认出我..非常感谢..

关于file - 改造分段上传图片失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28348269/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com