Closed hoangdangduy closed 4 years ago
Is the file a valid video file? It looks like the API was not able to verify the file. Are you able to upload the file via the Google Photos website or a mobile app?
What is the exact codec, dimensions, bit rate, etc. of the file? On Linux, you can use the tool mediainfo
to get a list of details about the file.
Is the file a valid video file? It looks like the API was not able to verify the file. Are you able to upload the file via the Google Photos website or a mobile app?
What is the exact codec, dimensions, bit rate, etc. of the file? On Linux, you can use the tool
mediainfo
to get a list of details about the file.
That video is a valid video. I try upload direct from website google photo and application About Backup and Sync was downloaded (https://www.google.com/drive/download/backup-and-sync/) together return success result, but with api return fail.
File test I uploaded to google drive. Please download and try it. https://drive.google.com/open?id=13NrGvHS1Bq54aRdhq4Ng7ufIKu5lrItt
Hope you soon reply. Thanks!!
@hoangdangduy Can you share the snippet of code where you are making the call? Are you setting the filename as well? (That's always recommended when uploading video or image files.)
@jfschmakeit I still use code in your repository sample code.
Optional
credentialsFile = FileUtils.readFileCredential();
try {
PhotosLibraryClient photosLibraryClient =
PhotosLibraryClientFactory.createClient(credentialsFile.get(), REQUIRED_SCOPES);
// Create a new upload request
// Specify the filename that will be shown to the user in Google Photos
// and the path to the file that will be uploaded
UploadMediaItemRequest uploadRequest = null;
for (DetailFile detailFile: lstDetailFile) {
String path = detailFile.getPath();
String fileName = detailFile.getFileName();
String[] arrSplitFileName = fileName.split("\\.");
try {
RandomAccessFile randomAccessFile = new RandomAccessFile(path, "r");
uploadRequest = UploadMediaItemRequest.newBuilder()
.setFileName(fileName)
.setDataFile(randomAccessFile)
.build();
// Upload and capture the response
UploadMediaItemResponse uploadResponse = photosLibraryClient.uploadMediaItem(uploadRequest);
if (uploadResponse.getError().isPresent()) {
// If the upload results in an error, handle it
UploadMediaItemResponse.Error error = uploadResponse.getError().get();
} else {
// If the upload is successful, get the uploadToken
String uploadToken = uploadResponse.getUploadToken().get();
NewMediaItem newMediaItem = NewMediaItemFactory
.createNewMediaItem(uploadToken, fileName);
List<NewMediaItem> newItems = Arrays.asList(newMediaItem);
BatchCreateMediaItemsResponse response = photosLibraryClient.batchCreateMediaItems(newItems);
randomAccessFile.close();
for (NewMediaItemResult itemsResponse : response.getNewMediaItemResultsList()) {
Status status = itemsResponse.getStatus();
if (status.getCode() == Code.OK_VALUE) {
// The item is successfully created in the user's library
System.out.println("Upload success");
MediaItem createdItem = itemsResponse.getMediaItem();
if (createdItem.getMimeType().compareToIgnoreCase("video/mp4") == 0) {
} else if (createdItem.getMimeType().compareToIgnoreCase("image/png") == 0) {
}
} else {
System.out.println("Upload fail");
}
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
} catch (ApiException e) {
e.printStackTrace();
// Handle error
} catch (FileNotFoundException e) {
// Local file could not be found for upload
e.printStackTrace();
} catch (GeneralSecurityException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
@jfschmakeit I'm still not yet upload file .mkv done from my code . If you have sample code upload file mkv in project so can it be run show for me. ? Thanks so much!
With file extension .mp4 upload don't have error but .mkv it's opposite. When I debug I still see token exist in UploadMediaItemResponse but when run through BatchCreateMediaItemsResponse.getNewMediaItemResultsList() it return code of status is 3 with message: "NOT_IMAGE: There was an error while trying to create this media item."
Did I do something wrong or code don't support that file ?