I've been working on App that allows to open files for which Google Drive cannot generate thumbnails, but the app I'm working on can. I've been following this article: https://developers.google.com/drive/api/v3/file#uploading_thumbnails and have the following code in my app as a result:
File file = drive.files().get(fileId).setFields("id,name,headRevisionId,hasThumbnail,contentHints").execute();
if (file != null && file.getHeadRevisionId().equals(versionId)) {
File.ContentHints.Thumbnail customThumbnail = new File.ContentHints.Thumbnail();
customThumbnail.encodeImage(imageData);
customThumbnail.setMimeType("image/png");
File.ContentHints contentHints = new File.ContentHints();
contentHints.setThumbnail(customThumbnail);
drive.files().update(fileId, new File().setContentHints(contentHints)).execute();
}
Image exists - imageData is byte[] and it has proper data in it. It seems that Google Drive retrieves this data because if I try to open preview of the file I've uploaded thumbnail for (on drive.google.com) - it tries to load it, but constantly shows "Failed, retrying".
If I do "non-safe" base64 encoding - I'm able to open this image URL in browser and any viewer and I've tried to pass this "non-safe" base64 encoded string, but the result is the same.
Is there something wrong with my code or I'm missing something in documentation or it's an issue on Google Drive side?
Related
I know that there is a function called getSubTransfers for the MultipleFileUpload, which I can use to retrieve the path of the file being uploaded to the AWS S3 bucket. I did my research and found nothing similar for the MultipleFileDownload. Here is the code that I used for Upload.
MultipleFileUpload upload = transferManager.uploadDirectory(bucket, cloudDir, localFolder, true);
Collection<? extends Upload> uploads = new ArrayList<Upload>();
uploads = upload.getSubTransfers();
for (Upload u : uploads)
{
System.out.println(u.getDescription());
}
Here is the code that I have for downloading the directory from S3:
MultipleFileDownload download = transferManager.downloadDirectory(bucket, cloudDir + "/", localFolder);
I am writing a client app in java that would print out the path of the current file being downloaded to the console. Any help on how to print the name of the current file being downloaded is appreciated.
Unfortunately it looks like this is not supported currently.
There is a github request for this exact feature - https://github.com/aws/aws-sdk-java/issues/785
The good news is that it is being worked on - https://github.com/aws/aws-sdk-java-v2/issues/37
The closest workaround I can think of using the SDK is to use Transfer.getProgress() which will give you a TransferProgress object. Which has some properties like percentTransfered and some others... https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/transfer/TransferProgress.html
I have a EBCDIC file from which i extracted images. However, there is some data on the images which is key source in identifying my transactions.
Assume that i have an image as "stackoverflow logo" stored under name "img1.jpg" on my desktop and when i read it using the following code, it works
String inputImage = "C:\\Desktop\\img1.jpg";
File imageFile = new File(inputImage);
BufferedImage image1 = ImageIO.read(imageFile);
System.out.println(image1);
However, when i attempt the same with an image decoded from EBCDIC conversion, it returns null.
The difference i observed is that there is no color associated in the decoded image. Is there any way to read these images and retrieve the text on the image. Following is not the exact image which i am working on, but just to give an idea i am sharing a sample from internet.
Note: The image am working on looks like a Scanned image (Grayscale)
Example:
Also, I observed that if i open the decode file and do a screen capture via snipping tool and store it as jpg file (which already is jpg) and read it, system is reading that file. not sure where is the issue, is it compression or color coding or format.
Thank you everyone.
I used Tess4j to decode the TIFF image. Unfortunately the information i was looking for isn't available in the decoded text. But, done with the POC.
used the following library and added eng.traineddata in the folder where images exist
import net.sourceforge.tess4j.*;
String inputImage = "C:\\Desktop\\img1.tiff";
File imageFile = new File(inputImage);
ITesseract imageRead = new Tesseract();
imageRead.setDataPath("C:\\Desktop\\");
imageRead.setLanguage("eng");
String imageText = imageRead.doOCR(imageFile);
System.out.println(imageText);
We have a Cordova app. I am getting an Image passed to me which is saved in the cache.
I need to make a file from a string url:
File pictureFile = new File(fileURL)
However when I try to load that image file it keeps failing (file not found).
A sample of what I am passed is this:
file:///data/data/co.appname.app/cache/tfss-4cb94488-1843-4ad3-8d02-8802008c7186-1685720347.jpg
I have tried making the following urls and none work when I create a file
/data/data/co.appname.app/files/tfss-4cb94488-1843-4ad3-8d02-8802008c7186-1685720347.jpg
file:/data/data/co.appname.app/files/tfss-4cb94488-1843-4ad3-8d02-8802008c7186-1685720347.jpg
I also tried taking just the file name tfss-4cb94488-1843-4ad3-8d02-8802008c7186-1685720347.jpg and getting the cached directory directly and that didn't work either
String path = getFilesDir().getAbsolutePath() + tfss-4cb94488-1843-4ad3-8d02-8802008c7186-1685720347.jpg
That just ends up with /data/data/co.appname.app/files/tfss-4cb94488-1843-4ad3-8d02-8802008c7186-1685720347.jpg which still comes up null.
The image HAS to exist there though because we are uploading it to Twitter and Cordova is saving the image in the cache.
Can you advise what the issue might be?
I needed to call getCacheDir() not getFilesDir().
I have been wrestling with this all night . Here's the issue I am using the google places api in my android project and want to use the icons provided in the json output. I have looked at the questions already posed and they all refer to javascript. Essentially in the log file it keeps stating that it can't find the file when I attempt to access this path. I can put the uri in the browse and it show up any ideas?
the uri is http://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png and heres the code it gives a warning too and when the marker is added (because its null errors out)
private Bitmap getBitmapFromUri(Uri uri) throws IOException {
AssetFileDescriptor FDescriptor =
//getContentResolver().openFileDescriptor(uri, "r");
getContentResolver().openAssetFileDescriptor(uri, "r");
FileDescriptor fileDescriptor = FDescriptor.getFileDescriptor();
Bitmap image = BitmapFactory.decodeFileDescriptor(fileDescriptor);
FDescriptor.close();
return image;
}
any help would be greatly appreciated
See the documentation for openAssetFileDescriptor. It doesn't handle the http scheme. You will probably either want to download this file manually and then use a method like the above to load a local file or use a library like Picasso, which will download and cache the image for you (and even load it into your ImageView).
I have a byte[] of an image and I need to upload it as an image to picasa.
According to the documentation, an image is uploaded as follows.
MediaFileSource myMedia = new MediaFileSource(new File("lights.jpg"), "image/jpeg");
which means I need to create a File, out of the byte[].
The catch is, I have to do this without using FileOutputStream as it is not supported by Google App Engine (which is the environment I am using)
Is there any way to do this?
You don't have to use MediaFileSource to upload a photo, you can use MediaByteArraySource and pass it to photo.setMediaSource(...).