Skip to content

Instantly share code, notes, and snippets.

@leeyc09
Created March 8, 2017 01:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leeyc09/1543ee48feaec585f44ccaf7a765a878 to your computer and use it in GitHub Desktop.
Save leeyc09/1543ee48feaec585f44ccaf7a765a878 to your computer and use it in GitHub Desktop.
retrofit upload 1
/**
* 파일 업로드 -1
* @Body에 parameter를 모두 추가하는 방법
*/
@POST("app/item/upload")
Observable<JsonObject> FileUpload_test(@Body RequestBody params);
RequestBody requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("node", MY_FOLDER_NODE)
.addFormDataPart("uploadkey","Filedata")
.addFormDataPart("Filedata", FOLDERLIST_FILENAME, RequestBody.create(
MediaType.parse("your file MIMETYPE ex)text/plain "), file)) //업로드 하려는 MIME 타입으로 설정해주세요.
.build();
RestfulAdapter.getInterface().FileUpload_test(requestBody) ~~ 이하 생략
/**
* 파일 업로드 -2
* @PartMap을 사용하는 방식
*/
@Multipart
@POST("app/item/upload")
Observable<JsonObject> FileUpload(@PartMap Map<String, RequestBody> params);
Map<String, RequestBody> map = new HashMap<>();
map.put("node", DownloadUtils.toRequestBody(node));
map.put("uploadkey", DownloadUtils.toRequestBody("Filedata"));
File file = new File(saveDirPath);
RequestBody fileBody = RequestBody.create(MediaType.parse("text/plain"), file);
map.put("Filedata\"; filename=\""+FileName, fileBody);
DCB_RestfulAdapter.getInterface().FileUpload(map) ~~ 이하 생략
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment