Upload a photo from an InputStream.

@param in
@param metaData
@return photoId or ticketId
@throws FlickrException
422141
@Override
    public String upload(InputStream in, UploadMetaData metaData) throws FlickrException {
        Payload payload = new Payload(in);
        return sendUploadRequest(metaData, payload);
    }
1032377
@Override
    public com.flickr4java.flickr.Response post(String path, Map<String, Object> parameters, String apiKey, String sharedSecret) throws FlickrException {

        OAuthRequest request = new OAuthRequest(Verb.POST, buildUrl(path));

        buildNormalPostRequest(parameters, request);

        OAuth10aService service = createAndSignRequest(apiKey, sharedSecret, request);

        try {
            return handleResponse(request, service);
        } catch (IllegalAccessException | InterruptedException | ExecutionException | InstantiationException | IOException | SAXException | ParserConfigurationException e) {
            throw new FlickrRuntimeException(e);
        }
    }
383655
public void orderSets(String[] photosetIds) throws FlickrException {
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("method", METHOD_ORDER_SETS);
        ;

        parameters.put("photoset_ids", StringUtilities.join(photosetIds, ","));

        Response response = transportAPI.post(transportAPI.getPath(), parameters, apiKey, sharedSecret);
        if (response.isError()) {
            throw new FlickrException(response.getErrorCode(), response.getErrorMessage());
        }
    }
282895
public void removePhoto(String photosetId, String photoId) throws FlickrException {
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("method", METHOD_REMOVE_PHOTO);

        parameters.put("photoset_id", photosetId);
        parameters.put("photo_id", photoId);

        Response response = transportAPI.post(transportAPI.getPath(), parameters, apiKey, sharedSecret);
        if (response.isError()) {
            throw new FlickrException(response.getErrorCode(), response.getErrorMessage());
        }
    }
959626
public Permissions getPerms(String photoId) throws FlickrException {
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("method", METHOD_GET_PERMS);

        parameters.put("photo_id", photoId);

        Response response = transport.get(transport.getPath(), parameters, apiKey, sharedSecret);
        if (response.isError()) {
            throw new FlickrException(response.getErrorCode(), response.getErrorMessage());
        }
        Element permissionsElement = response.getPayload();
        Permissions permissions = new Permissions();
        permissions.setId(permissionsElement.getAttribute("id"));
        permissions.setPublicFlag("1".equals(permissionsElement.getAttribute("ispublic")));
        permissions.setFamilyFlag("1".equals(permissionsElement.getAttribute("isfamily")));
        permissions.setFriendFlag("1".equals(permissionsElement.getAttribute("isfriend")));
        permissions.setComment(permissionsElement.getAttribute("permcomment"));
        permissions.setAddmeta(permissionsElement.getAttribute("permaddmeta"));
        return permissions;
    }
1281294
public BufferedImage getImage(String urlStr) throws FlickrException {
        InputStream in = null;
        try {
            URL url = new URL(urlStr);
            HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
            if (transport instanceof REST) {
                if (((REST) transport).isProxyAuth()) {
                    conn.setRequestProperty("Proxy-Authorization", "Basic " + ((REST) transport).getProxyCredentials());
                }
            }
            conn.connect();
            in = conn.getInputStream();
            return ImageIO.read(in);
        } catch (IOException e) {
            throw new FlickrException(e.getMessage(), e.getCause());
        } finally {
            IOUtilities.close(in);
        }
    }
637459
public PhotoAllContext getAllContexts(String photoId) throws FlickrException {
        PhotoSetList<PhotoSet> setList = new PhotoSetList<PhotoSet>();
        PoolList<Pool> poolList = new PoolList<Pool>();
        PhotoAllContext allContext = new PhotoAllContext();

        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("method", METHOD_GET_ALL_CONTEXTS);

        parameters.put("photo_id", photoId);

        Response response = transport.get(transport.getPath(), parameters, apiKey, sharedSecret);
        if (response.isError()) {
            throw new FlickrException(response.getErrorCode(), response.getErrorMessage());
        }
        Collection<Element> photosElement = response.getPayloadCollection();

        for (Element setElement : photosElement) {
            if (setElement.getTagName().equals("set")) {
                PhotoSet pset = new PhotoSet();
                pset.setTitle(setElement.getAttribute("title"));
                pset.setSecret(setElement.getAttribute("secret"));
                pset.setId(setElement.getAttribute("id"));
                pset.setFarm(setElement.getAttribute("farm"));
                pset.setPrimary(setElement.getAttribute("primary"));
                pset.setServer(setElement.getAttribute("server"));
                pset.setViewCount(Integer.parseInt(setElement.getAttribute("view_count")));
                pset.setCommentCount(Integer.parseInt(setElement.getAttribute("comment_count")));
                pset.setCountPhoto(Integer.parseInt(setElement.getAttribute("count_photo")));
                pset.setCountVideo(Integer.parseInt(setElement.getAttribute("count_video")));
                setList.add(pset);
                allContext.setPhotoSetList(setList);
            } else if (setElement.getTagName().equals("pool")) {
                Pool pool = new Pool();
                pool.setTitle(setElement.getAttribute("title"));
                pool.setId(setElement.getAttribute("id"));
                pool.setUrl(setElement.getAttribute("url"));
                pool.setIconServer(setElement.getAttribute("iconserver"));
                pool.setIconFarm(setElement.getAttribute("iconfarm"));
                pool.setMemberCount(Integer.parseInt(setElement.getAttribute("members")));
                pool.setPoolCount(Integer.parseInt(setElement.getAttribute("pool_count")));
                poolList.add(pool);
                allContext.setPoolList(poolList);
            }
        }

        return allContext;

    }
382044
public String uploadFile(byte[] file, String ext, Map<String, String> metaInfo) {
        String path = "";
        TrackerServer trackerServer = null;
        StorageClient1 storageClient1 = null;
        try {
            trackerServer = fastDfsClientPool.borrowObject();
            storageClient1 = new StorageClient1(trackerServer, null);
            NameValuePair data[] = null;
            if (Lang.isNotEmpty(metaInfo)) {
                data = new NameValuePair[metaInfo.size()];
                int index = 0;
                for (Map.Entry<String, String> entry : metaInfo.entrySet()) {
                    data[index] = new NameValuePair(entry.getKey(), entry.getValue());
                    index++;
                }
            }
            path = storageClient1.uploadFile1(file, ext, data);
        } catch (Exception e) {
            throw Lang.makeThrow("[FastdfsService] upload file error : %s", e.getMessage());
        } finally {
            if (trackerServer != null)
                fastDfsClientPool.returnObject(trackerServer);
            storageClient1 = null;
        }
        return path;
    }
1098862
public Photo getListPhoto(String photoId) throws FlickrException {

        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("method", METHOD_GET_LIST_PHOTO);

        parameters.put("photo_id", photoId);

        Response response = transportAPI.get(transportAPI.getPath(), parameters, apiKey, sharedSecret);
        if (response.isError()) {
            throw new FlickrException(response.getErrorCode(), response.getErrorMessage());
        }

        Element photoElement = response.getPayload();
        Photo photo = new Photo();
        photo.setId(photoElement.getAttribute("id"));

        List<Tag> tags = new ArrayList<Tag>();
        Element tagsElement = (Element) photoElement.getElementsByTagName("tags").item(0);
        NodeList tagElements = tagsElement.getElementsByTagName("tag");
        for (int i = 0; i < tagElements.getLength(); i++) {
            Element tagElement = (Element) tagElements.item(i);
            Tag tag = new Tag();
            tag.setId(tagElement.getAttribute("id"));
            tag.setAuthor(tagElement.getAttribute("author"));
            tag.setAuthorName(tagElement.getAttribute("authorname"));
            tag.setRaw(tagElement.getAttribute("raw"));
            tag.setValue(((Text) tagElement.getFirstChild()).getData());
            tags.add(tag);
        }
        photo.setTags(tags);
        return photo;
    }
1109853
public void postPhoto(Photo photo, String blogId) throws FlickrException {
        postPhoto(photo, blogId, null);
    }
148211
public void editPhotos(String photosetId, String primaryPhotoId, String[] photoIds) throws FlickrException {
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("method", METHOD_EDIT_PHOTOS);

        parameters.put("photoset_id", photosetId);
        parameters.put("primary_photo_id", primaryPhotoId);
        parameters.put("photo_ids", StringUtilities.join(photoIds, ","));

        Response response = transportAPI.post(transportAPI.getPath(), parameters, apiKey, sharedSecret);
        if (response.isError()) {
            throw new FlickrException(response.getErrorCode(), response.getErrorMessage());
        }
    }
1374406
@Override
    public com.flickr4java.flickr.Response postMultiPart(String path, UploadMetaData metaData, Payload payload, String apiKey, String sharedSecret) throws FlickrException {

        OAuthRequest request = new OAuthRequest(Verb.POST, buildUrl(path));
        Map<String, String> uploadParameters = new HashMap<>(metaData.getUploadParameters());

        buildMultipartRequest(uploadParameters, request);

        OAuth10aService service = createAndSignRequest(apiKey, sharedSecret, request);

        // Ensure all parameters (including oauth) are added to payload so signature matches
        uploadParameters.putAll(request.getOauthParameters());

        request.addMultipartPayload(String.format("form-data; name=\"photo\"; filename=\"%s\"", metaData.getFilename()), metaData.getFilemimetype(), payload.getPayload());
        uploadParameters.entrySet().forEach(e ->
                request.addMultipartPayload(String.format("form-data; name=\"%s\"", e.getKey()), null, e.getValue().getBytes()));

        try {
            return handleResponse(request, service);
        } catch (IllegalAccessException | InterruptedException | ExecutionException | InstantiationException | IOException | SAXException | ParserConfigurationException e) {
            throw new FlickrRuntimeException(e);
        }
    }
773597
private IIOMetadataNode createNewExifNode( IIOMetadata tiffMetadata, IIOMetadata thumbMeta, BufferedImage thumbnail ) {

        IIOMetadataNode app1Node = null;
        ImageWriter tiffWriter = null;
        try {
            Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("tiff");
            while( writers.hasNext() ) {
                tiffWriter = writers.next();
                if (tiffWriter.getClass().getName().startsWith("com.sun.media")) {
                    // Break on finding the core provider.
                    break;
                }
            }
            if (tiffWriter == null) {
                System.out.println("Cannot find core TIFF writer!");
                System.exit(0);
            }

            ImageWriteParam writeParam = tiffWriter.getDefaultWriteParam();
            writeParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
            writeParam.setCompressionType("EXIF JPEG");

            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            MemoryCacheImageOutputStream app1EXIFOutput = new MemoryCacheImageOutputStream(baos);
            tiffWriter.setOutput(app1EXIFOutput);

            // escribir
            tiffWriter.prepareWriteEmpty(jpegReader.getStreamMetadata(), new ImageTypeSpecifier(image), image.getWidth(),
                    image.getHeight(), tiffMetadata, null, writeParam);

            tiffWriter.endWriteEmpty();

            // Flush data into byte stream.
            app1EXIFOutput.flush();

            // Create APP1 parameter array.
            byte[] app1Parameters = new byte[6 + baos.size()];

            // Add EXIF APP1 ID bytes.
            app1Parameters[0] = (byte) 'E';
            app1Parameters[1] = (byte) 'x';
            app1Parameters[2] = (byte) 'i';
            app1Parameters[3] = (byte) 'f';
            app1Parameters[4] = app1Parameters[5] = (byte) 0;

            // Append TIFF stream to APP1 parameters.
            System.arraycopy(baos.toByteArray(), 0, app1Parameters, 6, baos.size());

            // Create the APP1 EXIF node to be added to native JPEG image metadata.
            app1Node = new IIOMetadataNode("unknown");
            app1Node.setAttribute("MarkerTag", (new Integer(0xE1)).toString());
            app1Node.setUserObject(app1Parameters);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (tiffWriter != null)
                tiffWriter.dispose();
        }

        return app1Node;

    }
764573
public PhotoList<Photo> getUntagged(int perPage, int page) throws FlickrException {
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("method", METHOD_GET_UNTAGGED);

        if (perPage > 0) {
            parameters.put("per_page", Integer.toString(perPage));
        }
        if (page > 0) {
            parameters.put("page", Integer.toString(page));
        }

        Response response = transport.get(transport.getPath(), parameters, apiKey, sharedSecret);
        if (response.isError()) {
            throw new FlickrException(response.getErrorCode(), response.getErrorMessage());
        }
        Element photosElement = response.getPayload();
        PhotoList<Photo> photos = PhotoUtils.createPhotoList(photosElement);
        return photos;
    }
440417
public PhotoContext getContext(String photoId, String groupId) throws FlickrException {
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("method", METHOD_GET_CONTEXT);

        parameters.put("photo_id", photoId);
        parameters.put("group_id", groupId);

        Response response = transport.get(transport.getPath(), parameters, apiKey, sharedSecret);
        if (response.isError()) {
            throw new FlickrException(response.getErrorCode(), response.getErrorMessage());
        }
        Collection<Element> payload = response.getPayloadCollection();
        PhotoContext photoContext = new PhotoContext();
        for (Element element : payload) {
            String elementName = element.getTagName();
            if (elementName.equals("prevphoto")) {
                Photo photo = new Photo();
                photo.setId(element.getAttribute("id"));
                photoContext.setPreviousPhoto(photo);
            } else if (elementName.equals("nextphoto")) {
                Photo photo = new Photo();
                photo.setId(element.getAttribute("id"));
                photoContext.setNextPhoto(photo);
            } else if (!elementName.equals("count")) {
                _log.warn("unsupported element name: " + elementName);
            }
        }
        return photoContext;
    }
960054
private StorePath uploadFileAndMetaData(StorageNode client, InputStream inputStream, long fileSize,
                                            String fileExtName, Set<MetaData> metaDataSet) {
        // 上传文件
        StorageUploadFileCommand command = new StorageUploadFileCommand(client.getStoreIndex(), inputStream,
                fileExtName, fileSize, false);
        StorePath path = connectionManager.executeFdfsCmd(client.getInetSocketAddress(), command);
        // 上传metadata
        if (hasMetaData(metaDataSet)) {
            StorageSetMetadataCommand setMDCommand = new StorageSetMetadataCommand(path.getGroup(), path.getPath(),
                    metaDataSet, StorageMetadataSetType.STORAGE_SET_METADATA_FLAG_OVERWRITE);
            connectionManager.executeFdfsCmd(client.getInetSocketAddress(), setMDCommand);
        }
        return path;
    }
779642
public void addMetadata(Metadata meta) {
    for (String k : meta.keySet()) {
      for (TiffObject to : meta.getList(k)) {
        add(k, to, meta.getMetadataObject(k).isDublinCore(), meta.getMetadataObject(k).getPath());
      }
    }
  }