@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PhotoModel that = (PhotoModel) o; return Objects.equal(getTitle(), that.getTitle()) && Objects.equal(getFetchableUrl(), that.getFetchableUrl()) && Objects.equal(getDescription(), that.getDescription()) && Objects.equal(getMediaType(), that.getMediaType()) && Objects.equal(getDataId(), that.getDataId()) && Objects.equal(getAlbumId(), that.getAlbumId()); } }
SmugMugImageUploadResponse uploadImage(PhotoModel photoModel, String albumUri, InputStream inputStream) throws IOException { // Set up photo InputStreamContent content = new InputStreamContent(null, inputStream); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); content.writeTo(outputStream); byte[] contentBytes = outputStream.toByteArray(); // Headers from: https://api.smugmug.com/api/v2/doc/reference/upload.html Map<String, String> headersMap = new HashMap<>(); headersMap.put("X-Smug-AlbumUri", albumUri); headersMap.put("X-Smug-ResponseType", "JSON"); headersMap.put("X-Smug-Version", "v2"); headersMap.put("Content-Type", photoModel.getMediaType()); if (!Strings.isNullOrEmpty(photoModel.getTitle())) { headersMap.put("X-Smug-Title", photoModel.getTitle()); } if (!Strings.isNullOrEmpty(photoModel.getDescription())) { headersMap.put("X-Smug-Caption", photoModel.getDescription()); } // Upload photo return postRequest( "https://upload.smugmug.com/", ImmutableMap.of(), // No content params for photo upload contentBytes, headersMap, new TypeReference<SmugMugImageUploadResponse>() { }); }
if (Strings.isNullOrEmpty(inputPhoto.getDescription())) { description = ""; } else { description = COPY_PREFIX + inputPhoto.getDescription();
@Test public void toCommonPhoto() { Photo photo = FlickrTestUtils.initializePhoto(PHOTO_TITLE, FETCHABLE_URL, PHOTO_DESCRIPTION, MEDIA_TYPE); PhotoModel photoModel = FlickrPhotosExporter.toCommonPhoto(photo, ALBUM_ID); assertThat(photoModel.getAlbumId()).isEqualTo(ALBUM_ID); assertThat(photoModel.getFetchableUrl()).isEqualTo(FETCHABLE_URL); assertThat(photoModel.getTitle()).isEqualTo(PHOTO_TITLE); assertThat(photoModel.getDescription()).isEqualTo(PHOTO_DESCRIPTION); assertThat(photoModel.getMediaType()).isEqualTo("image/jpeg"); }
private String uploadPhoto(PhotoModel photo) throws IOException, FlickrException { BufferedInputStream inStream = imageStreamProvider.get(photo.getFetchableUrl()); UploadMetaData uploadMetaData = new UploadMetaData() .setAsync(false) .setPublicFlag(false) .setFriendFlag(false) .setFamilyFlag(false) .setTitle(COPY_PREFIX + photo.getTitle()) .setDescription(photo.getDescription()); return uploader.upload(inStream, uploadMetaData); }
@Override public ImportResult importItem( UUID jobId, TokenSecretAuthData authData, PhotosContainerResource data) { Twitter twitterApi = TwitterApiWrapper.getInstance(appCredentials, authData); // Twitter doesn't support an 'Albums' concept, so that information is just lost. for (PhotoModel image : data.getPhotos()) { try { StatusUpdate update = new StatusUpdate(image.getDescription()); InputStreamContent content = new InputStreamContent(null, getImageAsStream(image.getFetchableUrl())); update.media(image.getTitle(), content.getInputStream()); twitterApi.tweets().updateStatus(update); } catch (IOException | TwitterException e) { monitor.severe(() -> "Error importing twitter photo", e); return new ImportResult(e); } } return new ImportResult(ResultType.OK); }