Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2010 MediaShelf <> This file is part of fedora-client. fedora-client is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. fedora-client is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with fedora-client. If not, see <>.
package com.yourmediashelf.fedora.client.request;
Builder for the Upload method.

The Fedora REST API upload method was introduced in Fedora 3.4

Edwin Shin
See also:
public class Upload extends FedoraRequest<Upload> {
    private final org.slf4j.Logger logger = org.slf4j.LoggerFactory
    private final File file;


file the file to upload
    public Upload(File file) {
        this. = file;
    public UploadResponse execute() throws FedoraClientException {
        return (UploadResponsesuper.execute();
    public UploadResponse execute(FedoraClient fedora)
            throws FedoraClientException {
        ClientResponse response = null;
        String path = String.format("upload");
        WebResource wr = resource(fedora).path(path);
        MediaType mediaType = MediaType.valueOf(fedora.getMimeType());
        MultiPart multiPart =
                new FormDataMultiPart().bodyPart(new FileDataBodyPart("file",
        // Check for a 302 (expected if baseUrl is http but Fedora is configured
        // to require SSL
        response = wr.head();
        if (response.getStatus() == 302) {
            URI newLocation = response.getLocation();
            .warn("302 status for upload request: " + newLocation);
            wr = resource(newLocation.toString());
        response =
        return new UploadResponse(response);
New to GrepCode? Check out our FAQ X