Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2010 MediaShelf <http://www.yourmediashelf.com/> 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 <http://www.gnu.org/licenses/>.
package com.yourmediashelf.fedora.client.request;
Builder for the Upload method.

The Fedora REST API upload method was introduced in Fedora 3.4

Author(s):
Edwin Shin
See also:
"http://www.fedora-commons.org/jira/browse/FCREPO-687"
public class Upload extends FedoraRequest<Upload> {
    private final org.slf4j.Logger logger = org.slf4j.LoggerFactory
            .getLogger(this.getClass());
    private final File file;

    

Parameters:
file the file to upload
    public Upload(File file) {
        this. = file;
    }
    @Override
    public UploadResponse execute() throws FedoraClientException {
        return (UploadResponsesuper.execute();
    }
    @Override
    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",
                        mediaType));
        // 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 =
                wr.queryParams(getQueryParams()).type(
                        .).post(
                        ClientResponse.classmultiPart);
        return new UploadResponse(response);
    }
New to GrepCode? Check out our FAQ X