Hi,

i want to implement an multipart upload for Google Drive to do something
like this [1]:

POST /upload/drive/v2/files?uploadType=multipart HTTP/1.1
Host: www.googleapis.com
Authorization: Bearer your_auth_token
Content-Type: multipart/related; boundary="foo_bar_baz"
Content-Length: number_of_bytes_in_entire_request_body

--foo_bar_baz
Content-Type: application/json; charset=UTF-8

{
  "title": "My File"
}

--foo_bar_baz
Content-Type: image/jpeg
JPEG data

--foo_bar_baz--

I build the header correctly but the content is my issue. So my first Step
was to implement the method call in my DriveAsyncClient:

    @Named("Files:insert")
    @POST
    @OAuthScopes(DriveConstants.DRIVE_SCOPE)
    @Path("upload/drive/v2/files")
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    @ResponseParser(ParseObjectFrom.class)
    ListenableFuture<DriveResponseUpload> putContentAndMetadata
(@BinderParam(BindUploadMetadataToContent.class) DriveObject object,
@QueryParam(value = "uploadType") String uploadType);

Next Step was to implement the BindUploadMetadataToContent and so i had to
try out the MultiPartForm like this one:

@Override
    public <R extends HttpRequest> R bindToRequest(R request, Object input) {
        checkArgument(checkNotNull(input, "input") instanceof
DriveObject, "this binder is only valid for DriveObject");

        DriveObject obj = DriveObject.class.cast(input);

        Part.PartOptions contentOptions = new
Part.PartOptions().contentType(obj.getMetadata().getContentMetadata().getContentType());
        contentOptions.filename(obj.getMetadata().getTitle());

        Part content = Part.create(obj.getMetadata().getTitle(),
obj.getPayload(), contentOptions);

        Part contentMetadata = Part.create(/*Content Metadata like Title*/);

        request.setPayload(new MultipartForm("foo_bar_baz", content,
contentMetadata));

        return request
}

The Question is, does the MultipartForm class still works and where is the
mistake?

Cheers,

Josh

[1] https://developers.google.com/drive/web/manage-uploads

Reply via email to