Giter Club home page Giter Club logo

Comments (5)

jfschmakeit avatar jfschmakeit commented on May 16, 2024

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.

from java-photoslibrary.

hoangdangduy avatar hoangdangduy commented on May 16, 2024

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!!

from java-photoslibrary.

jfschmakeit avatar jfschmakeit commented on May 16, 2024

@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.)

from java-photoslibrary.

hoangdangduy avatar hoangdangduy commented on May 16, 2024

@jfschmakeit I still use code in your repository sample code.

https://pastebin.com/JwHpD8QB

Optional<String> 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();
}

from java-photoslibrary.

hoangdangduy avatar hoangdangduy commented on May 16, 2024

@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!

from java-photoslibrary.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.