Java源码示例:retrofit.http.Multipart

示例1
@Multipart
@POST("/action/api/tweet_pub")
Call<RespResult> publicTweet(
        @Part("uid") RequestBody uid,
        @Part("msg") RequestBody message,
        @Part("img\"; filename=\"image.png\" ") RequestBody image,
        @Part("amr") RequestBody voice);
 
示例2
@Multipart
@Headers({"Content-Type: multipart/form-data",
        "Accept: application/json",
        "Accept-Encoding: gzip, deflate"})
@POST("/api/{userID}/violation/create")
VideoAnswer uploadImage(@Part("photo") TypedFile photo,
                        @EncodedPath("userID") String userID,
                        @Part("latitude") double latitude,
                        @Part("longitude") double longitude);
 
示例3
@Multipart
@POST("/nudge/api/{version}/users/@me/meals")
void createMealEvent(
    @Path(UpPlatformSdkConstants.API_VERSION) String version,
    @PartMap HashMap<String, Object> hashMap,
    Callback<Object> response
);
 
示例4
@Multipart
@POST("/nudge/api/{version}/meals/{xid}/partialUpdate")
void updateMealEvent(
    @Path(UpPlatformSdkConstants.API_VERSION) String version,
    @Path(UpPlatformSdkConstants.XID) String xid,
    @PartMap HashMap<String, Object> hashMap,
    Callback<Object> response
);
 
示例5
@Multipart
@POST("/nudge/api/{version}/users/@me/generic_events")
void createCustomEvent(
    @Path(UpPlatformSdkConstants.API_VERSION) String version,
    @PartMap HashMap<String, Object> hashMap,
    Callback<Object> response
);
 
示例6
@Multipart
@POST("/nudge/api/{version}/generic_events/{xid}/partialUpdate")
void updateCustomEvent(
    @Path(UpPlatformSdkConstants.API_VERSION) String version,
    @PartMap HashMap<String, Object> hashMap,
    Callback<Object> response
);
 
示例7
@Multipart
@POST("/nudge/api/{version}/users/@me/workouts")
void createWorkoutEvent(
    @Path(UpPlatformSdkConstants.API_VERSION) String version,
    @PartMap HashMap<String, Object> hashMap,
    Callback<Object> response
);
 
示例8
@Multipart
@POST("/nudge/api/{version}/workouts/{xid}/partialUpdate")
void updateWorkoutEvent(
    @Path(UpPlatformSdkConstants.API_VERSION) String version,
    @PartMap HashMap<String, Object> hashMap,
    Callback<Object> response
);
 
示例9
@Multipart
@POST("/nudge/api/{version}/users/@me/sleeps")
void createSleepEvent(
    @Path(UpPlatformSdkConstants.API_VERSION) String version,
    @PartMap HashMap<String, Object> hashMap,
    Callback<Object> response
);
 
示例10
@Multipart
@POST("/nudge/api/{version}/users/@me/body_events")
void createBodyEvent(
    @Path(UpPlatformSdkConstants.API_VERSION) String version,
    @PartMap HashMap<String, Object> hashMap,
    Callback<Object> response
);
 
示例11
@Multipart
@POST("/nudge/api/{version}/users/@me/goals")
void createOrUpdateUsersGoals(
    @Path(UpPlatformSdkConstants.API_VERSION) String version,
    @PartMap HashMap<String, Object> hashMap,
    Callback<Object> response
);
 
示例12
@Multipart
@POST("/nudge/api/{version}/users/@me/mood")
void createMoodEvent(
        @Path(UpPlatformSdkConstants.API_VERSION) String version,
        @PartMap HashMap<String, Object> hashMap,
        Callback<Object> response
);
 
示例13
@Multipart
@POST("/nudge/api/{version}/users/@me/refreshToken")
void getRefreshToken(
        @Path(UpPlatformSdkConstants.API_VERSION) String version,
        @Part("secret") String clientSecret,
        Callback<Object> response
);
 
示例14
/**
 * <pre>
 * curl -k -X POST 'https://example.com/oauth2/token' -d 'code=aa5b25e58cb0ecbb1ddf5d671e769b04cabcdefg&state=8tory&grant_type=authorization_code&client_id=id&client_secret=secret'
 * </pre>
 */
@Multipart
@POST("/token")
void token(
    @Part("code") String code,
    @Part("client_id") String clientId,
    @Part("client_secret") String clientSecret,
    @Part("grant_type") String grantType,
    @Part("state") String state,
    Callback<Credential> callback
);
 
示例15
@Multipart
@POST("/token")
Credential token(
    @Part("code") String code,
    @Part("client_id") String clientId,
    @Part("client_secret") String clientSecret,
    @Part("grant_type") String grantType,
    @Part("state") String state
);
 
示例16
@Multipart
@POST("/token")
Observable<Credential> observeToken(
    @Part("code") String code,
    @Part("client_id") String clientId,
    @Part("client_secret") String clientSecret,
    @Part("grant_type") String grantType,
    @Part("state") String state
);
 
示例17
/**
 * <pre>
 * curl -k -X POST 'https://example.com/oauth2/token' -d 'grant_type=password&client_id=id&client_secret=secret&state=state&username=foo&password=bar'
 * </pre>
 */
@Multipart
@POST("/token")
void token(
    @Part("client_id") String clientId,
    @Part("client_secret") String clientSecret,
    @Part("grant_type") String grantType,
    @Part("state") String state,
    @Part("username") String username,
    @Part("password") String password,
    Callback<Credential> callback
);
 
示例18
@Multipart
@POST("/token")
Credential token(
    @Part("client_id") String clientId,
    @Part("client_secret") String clientSecret,
    @Part("grant_type") String grantType,
    @Part("state") String state,
    @Part("username") String username,
    @Part("password") String password
);
 
示例19
@Multipart
@POST("/token")
Observable<Credential> observeToken(
    @Part("client_id") String clientId,
    @Part("client_secret") String clientSecret,
    @Part("grant_type") String grantType,
    @Part("state") String state,
    @Part("username") String username,
    @Part("password") String password
);
 
示例20
@Multipart
@POST("/upload")
Observable<FileUploadResponseData> uploadFile(@Part("name") String name, @Part("type") String mimeType, @Part("size") long fileSize, @Part("file") TypedFile file);
 
示例21
@POST("/upload.webservices.aptoide.com/webservices/2/uploadAppToRepo")
@Multipart
UploadAppToRepoJson postApk(@PartMap HashMap<String, Object> args);
 
示例22
@Multipart
@POST("/shots/{id}/attachments")
Observable<Response> createShotAttachments(@Path("id") long id, @Part("file") TypedFile file);
 
示例23
@Multipart
@POST("/shots")
Observable<Response> createShot(@Part("image") TypedFile image, @Part("title") TypedString title, @Part("description") TypedString description);
 
示例24
@Multipart
@POST("/shots")
Observable<Response> createShot(@Part("image") TypedFile image, @Part("title") TypedString title, @Part("description") TypedString description, @Part("tags") TypedString tags);
 
示例25
@Multipart
@POST("/api/2/apps/{APP_ID}/crashes/upload")
void createEvent(@Path("APP_ID") String appId,
                 @Part("log") TypedFile log,
                 Callback<Response> callback
);
 
示例26
@Multipart
@POST(VIDEO_DATA_PATH)
public VideoStatus setVideoData(@Path(ID_PARAMETER) long id, @Part(DATA_PARAMETER) TypedFile videoData);
 
示例27
@Multipart
@PUT("/v1/devices/{deviceID}")
Response flashFile(@Path("deviceID") String deviceID,
                   @Part("file") TypedOutput file);
 
示例28
/**
 * Loads {@link #requestMethod} and {@link #requestType}.
 */
private void parseMethodAnnotations() {
    for (Annotation methodAnnotation : method.getAnnotations()) {
        Class<? extends Annotation> annotationType = methodAnnotation.annotationType();
        RestMethod methodInfo = null;

        // Look for a @RestMethod annotation on the parameter annotation indicating request method.
        for (Annotation innerAnnotation : annotationType.getAnnotations()) {
            if (RestMethod.class == innerAnnotation.annotationType()) {
                methodInfo = (RestMethod) innerAnnotation;
                break;
            }
        }

        if (methodInfo != null) {
            if (requestMethod != null) {
                throw new IllegalArgumentException("Method " + method.getName() + " contains multiple HTTP methods. Found: " + requestMethod + " and " + methodInfo.value());
            }
            String path;
            try {
                path = (String) annotationType.getMethod("value").invoke(methodAnnotation);
            } catch (Exception e) {
                throw new RuntimeException("Failed to extract path from " + annotationType.getSimpleName() + " annotation on " + method.getName() + ".", e);
            }
            parsePath(path);
            requestMethod = methodInfo.value();
            requestHasBody = methodInfo.hasBody();
        } else if (annotationType == Headers.class) {
            String[] headersToParse = ((Headers) methodAnnotation).value();
            if (headersToParse.length == 0) {
                throw new IllegalStateException("Headers annotation was empty.");
            }
            headers = parseHeaders(headersToParse);
        } else if (annotationType == Multipart.class) {
            if (requestType != RequestType.SIMPLE) {
                throw new IllegalStateException("Only one encoding annotation per method is allowed: " + method.getName());
            }
            requestType = RequestType.MULTIPART;
        } else if (annotationType == FormUrlEncoded.class) {
            if (requestType != RequestType.SIMPLE) {
                throw new IllegalStateException("Only one encoding annotation per method is allowed: " + method.getName());
            }
            requestType = RequestType.FORM_URL_ENCODED;
        }
    }

    if (requestMethod == null) {
        throw new IllegalStateException("Method " + method.getName() + " not annotated with request type (e.g., GET, POST).");
    }
    if (!requestHasBody) {
        if (requestType == RequestType.MULTIPART) {
            throw new IllegalStateException("Multipart can only be specific on HTTP methods with request body (e.g., POST). (" + method.getName() + ")");
        }
        if (requestType == RequestType.FORM_URL_ENCODED) {
            throw new IllegalStateException("Multipart can only be specific on HTTP methods with request body (e.g., POST). (" + method.getName() + ")");
        }
    }
}
 
示例29
/**
 * Creates a new page with a multi-part content body
 * in a section specified by section id
 *
 * @param version
 * @param sectionId
 * @param partMap
 * @param callback
 */
@Multipart
@POST("/{version}/me/notes/sections/{sectionId}/pages")
void postMultiPartPages(
        @Path("version") String version,
        @Path("sectionId") String sectionId,
        @PartMap OneNotePartsMap partMap,
        Callback<Envelope<Page>> callback
);
 
示例30
/**
 * Sends a POST request to Upload the Video data to the Video Web
 * service using a two-way Retrofit RPC call.  @Multipart is used
 * to transfer multiple content (i.e. several files in case of a
 * file upload to a server) within one request entity.  When doing
 * so, a REST client can save the overhead of sending a sequence
 * of single requests to the server, thereby reducing network
 * latency.
 * 
 * @param id
 * @param videoData
 * @return videoStatus indicating status of the uploaded video.
 */
@Multipart
@POST(VIDEO_DATA_PATH)
public VideoStatus setVideoData(@Path(ID_PARAMETER) long id,
                                @Part(DATA_PARAMETER) TypedFile videoData);