Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.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 改装2文件上载不附加文件_Android_File Upload_Asp.net Core_Retrofit - Fatal编程技术网

Android 改装2文件上载不附加文件

Android 改装2文件上载不附加文件,android,file-upload,asp.net-core,retrofit,Android,File Upload,Asp.net Core,Retrofit,我已经使用asp内核在服务器上编写了一个上传操作,并使用ARC和接收的文件对其进行了测试 但当我尝试上传图像时,没有收到任何消息。即使表单也是空的: 接口的源代码在这里。界面: public interface QuestionWebService { @Multipart @POST("questionapi/uploadfiles") Call<ResponseBody> uploadSync(@Part("fileUpload") RequestB

我已经使用asp内核在服务器上编写了一个上传操作,并使用ARC和接收的文件对其进行了测试

但当我尝试上传图像时,没有收到任何消息。即使表单也是空的:

接口的源代码在这里。界面:

public interface QuestionWebService {

    @Multipart
    @POST("questionapi/uploadfiles")
    Call<ResponseBody> uploadSync(@Part("fileUpload") RequestBody paramTypedFile);
}
你知道我该怎么做吗?我哪里做错了。
TG.

我终于找到了解决办法。我不知道该代码不起作用的原因,但如前所述,我更改了:

public interface QuestionWebService {

    @Multipart
    @POST("questionapi/uploadfiles")
    Call<ResponseBody> uploadSync(@Part("fileUpload") RequestBody paramTypedFile);
}
对于这一点:

public interface QuestionWebService {

    @Multipart
    @POST("questionapi/uploadfiles")
    Call<ResponseBody> uploadSync(@Part("UserId") RequestBody UserId, @Part("answer") RequestBody answer, @Part MultipartBody.Part file);
}
// create RequestBody instance from file
            RequestBody requestFile =
                    RequestBody.create(MediaType.parse("multipart/form-data"), fileToSend);

            // MultipartBody.Part is used to send also the actual file name
            MultipartBody.Part body =
                    MultipartBody.Part.createFormData("fileUpload", fileToSend.getName(), requestFile);
RequestBody userId =
                    RequestBody.create(
                            MediaType.parse("multipart/form-data"), userIdString);

            // add another part within the multipart request
            String answerString = "hello, this is answer speaking";
            RequestBody answer =
                    RequestBody.create(
                            MediaType.parse("multipart/form-data"), answerString);

            Response response = restClient.getQuestionService().uploadSync(userId, answer, body).execute();
现在一切都正常了!!! 我希望其他人也会遇到同样的问题

现在服务器上的数据是一个表单,包含两个字段:UserId和Answer,以及一个名为fileUpload的文件。
TG.

che hame soal deri shuma:D:-仅支持多部件部件类型的Pretrofit2data@Saveen您所说的零件类型数据是什么意思?什么是错误的,我应该改变什么?好的,这可能是愚蠢的,所以请随意忽略,但为什么上传的文件用绿色下划线标记?当我继承一个类,并且我有一个与我继承的类相同的方法名时,我经常看到这种情况。我只是好奇为什么VS会标记它。@Woot-我猜绿色下划线是因为函数是异步的,但不包含异步(即等待)调用。
RequestBody typedFile = RequestBody.create(MediaType.parse("image/*"), fileToSend);
            Response response = restClient.getQuestionService().uploadSync(typedFile).execute();
// create RequestBody instance from file
            RequestBody requestFile =
                    RequestBody.create(MediaType.parse("multipart/form-data"), fileToSend);

            // MultipartBody.Part is used to send also the actual file name
            MultipartBody.Part body =
                    MultipartBody.Part.createFormData("fileUpload", fileToSend.getName(), requestFile);
RequestBody userId =
                    RequestBody.create(
                            MediaType.parse("multipart/form-data"), userIdString);

            // add another part within the multipart request
            String answerString = "hello, this is answer speaking";
            RequestBody answer =
                    RequestBody.create(
                            MediaType.parse("multipart/form-data"), answerString);

            Response response = restClient.getQuestionService().uploadSync(userId, answer, body).execute();