在这里,我尝试在多部分请求中发送对象映射,但我的请求是字符串,而不是 JSON 格式,请建议我执行正确的请求。提前致谢。
我已经尝试过多部分请求,但我的请求应该采用正确的形式。
var getApiUrl = 'http://malik-env-test.ap-south-1.elasticbeanstalk.com/webapi/post/create';
Map userData = {
"creator": {
"creatorId": "298",
"createDate": "2018-12-21 20:44:45.8"
},
"info": "$campusInfo",
"title": "$eventName",
"postCampusId": "5642"
};
Run Code Online (Sandbox Code Playgroud)
Uri uri = Uri.parse(getApiUrl);
http.MultipartRequest request = new http.MultipartRequest('POST', uri);
request.fields['creator'] = userData['creator'];
request.fields['info'] = '$campusInfo';
request.fields['title'] = '$eventName';
request.fields['postCampusId'] = '5642';
request.files.add(await http.MultipartFile.fromPath('image_file1', imagePath, contentType: new MediaType('application', 'x-tar')));
// var body = json.encode(request);
print(request);
http.StreamedResponse response = await request.send();
String jsonData = response.toString();
print(jsonData);ddd
Run Code Online (Sandbox Code Playgroud) 我使用WebApi上传文件,但是当我运行时
request.Content.ReadAsMultipartAsync(provider)
Run Code Online (Sandbox Code Playgroud)
文件已上传,但其文件名已完全更改.我读过一些关于它的说法是出于安全原因而自动制作的.无论如何,我想用真实的文件名存储文件.知道怎么做吗?
我正在使用vertx.io编写用于多部分文件上载的代码.
在Spring启动时,我的代码如下.我想在vertex.io中写类似的东西
@RequestMapping(value = "/upload", headers=("content-type=multipart/*") ,method = RequestMethod.POST)
public ImportExportResponse upload(@RequestParam("file") MultipartFile inputFile){
log.info(" upload service method starts ");
ImportExportResponse response = new ImportExportResponse();
FileOutputStream fileOutputStream=null;
try{
File outputFile = new File(FILE_LOCATION+inputFile.getOriginalFilename());
fileOutputStream = new FileOutputStream(outputFile);
fileOutputStream.write(inputFile.getBytes());
fileOutputStream.close();
response.setStatus(ImportExportConstants.ResponseStatus.SUCCESS.name());
response.setErrorMessage(EMPTY);
}catch (Exception e) {
log.error("Exception while upload the file . "+e.getMessage());
response.setStatus(ImportExportConstants.ResponseStatus.ERROR.name());
response.setErrorMessage(errorMap.get(SYSTEM_ERROR_CODE));
}
log.info(" upload service method ends. file is copied to a temp folder ");
return response;
}
Run Code Online (Sandbox Code Playgroud) 我使用下面的代码向 http 服务器发送请求。
服务器发送包含这些 http 标头的响应
Content-Disposition:[attachment;filename=somefilename.csv]
Content-Type:[text/csv; charset=UTF-8]
Run Code Online (Sandbox Code Playgroud)
我如何继续检索响应所附文件的内容?
baseUrl := "Some url that i call to fetch csv file"
client := http.Client{}
resp, _ := client.Get(baseUrl)
defer resp.Body.Close()
fmt.Println(resp)
// &{200 OK 200 HTTP/2.0 2 0 map[Content-Disposition:[attachment;filename=somefilename.csv] Content-Type:[text/csv; charset=UTF-8] Date:[Mon, 30 Sep 2019 09:54:08 GMT] Server:[Jetty(9.2.z-SNAPSHOT)] Vary:[Accept]] {0xc000530280} -1 [] false false map[] 0xc000156200 0xc0000c26e0}
Run Code Online (Sandbox Code Playgroud)