How to get thumbnail from Dropboxapi using JAVA SDK? - java

I am working with Dropbox API using JAVA SDK. I try to get the thumbnail for each image in my dropbox account via API. Honestly, after I read the class and they just provided the description which is not useful enough for the beginner. I begin my code like this
public void getThumbnails() throws DropboxException{
DropboxInputStream dis = api.getThumbnailStream("/Koala.jpg", ThumbSize.ICON_256x256, ThumbFormat.JPEG);
}
What I don't understand is:
I should return something to client side in order to show the thumbnail I got from DropboxAPI but I don't know what I should return. Maybe DropboxInputStream?
How do I get the thumbnail from API? I try to find the example or guide for a day but I can't find any guide...
please someone guide me how to get the thumbnail via dropbox API

DropboxInputStream is just a FilterInputStream so after you get the input stream like you wrote you can just iterate the input stream and read it.
Then it's only a question of the way you need to present it.
Is it a Swing application you are writing? how do you need to show that image?

You should be able to read the Image with ImageIO.read
Image image = ImageIO.read(dis);
http://docs.oracle.com/javase/6/docs/api/javax/imageio/ImageIO.html

Related

apache commons imaging writing image error

Below is the sample code that is giving error with the microsoft sample pictures (tulips.jpg) image
bufferedImage = Imaging.getBufferedImage(new file("Tulips.jpg"));
File imageFile = new File("outputfile.jpg");
final Map<String, Object> optionalParams = new HashMap<String, Object>();
Imaging.writeImage(bufferedImage, imageFile, ImageFormats.JPEG, optionalParams);
This code is giving "This image format (Jpeg-Custom) cannot be written." Any pointers would be of great help. I have searched stackoverflow, google - no help so far.
When I read the documentation it states that if the bufferedImage.getType()== TYPE_UNKNOWN, it gives this message but dont have a clue why it is giving UNKNOWN.
Thanks so much for your help.
Write to JPEG files is not supported by Apache Commons Imaging. You can see supported format information here: http://commons.apache.org/proper/commons-imaging/formatsupport.html (even JPEG read is not fully supported). However write to some other formats supported (e.g. you can change image format to PNG in your writeImage function call and it will work).
Moreover Apache Commons Imaging is not released yet, so I wouldn't recommend using it in a critical code.
As alternative you can take a look into JDK javax.imageio.ImageIO class (some examples: https://docs.oracle.com/javase/tutorial/2d/images/saveimage.html).
What exactly are you trying to achieve in your code?

How to update the content of a file in Google Drive?

I am trying to update the content of a Google Doc file with the content of another Google Doc file. The reason I don't use the copy method of the API is because that creates another file with another ID. My goal is to keep the current ID of the file. This is a code snippet which unfortunately does nothing:
com.google.api.services.drive.Drive.Files.Get getDraft = service.files().get(draftID);
File draft = driveManager.getFileBackoffExponential(getDraft);
com.google.api.services.drive.Drive.Files.Update updatePublished = service.files().update(publishedID, draft);
driveManager.updateFileBackoffExponential(updatePublished);
The two backoffExponential functions just launch the execute method on the object.
Googling around I found out that the update method offers another constructor:
public Update update(java.lang.String fileId, com.google.api.services.drive.model.File content, com.google.api.client.http.AbstractInputStreamContent mediaContent)
Thing is, I have no idea how to retrieve the mediaContent of a Google file such as a Google Doc.
The last resort could be a Google Apps Script but I'd rather avoid that since it's awfully slow and unreliable.
Thank you.
EDIT: I am using Drive API v3.
Try the Google Drive REST update.
Updates a file's metadata and/or content with patch semantics.
This method supports an /upload URI and accepts uploaded media with
the following characteristics:
Maximum file size: 5120GB Accepted Media MIME types: /*
To download a Google File in the format that's usable, you need to specify the mime-type. Since you're using Spreadsheets, you can try application/vnd.openxmlformats-officedocument.spreadsheetml.sheet. Link to Download files for more info.

PHP webservice file upload & download logic with Android client

First, this is my first time building both of webservice and android client at the same time, so please kindly help me. My goal is to be able to upload a file from android apps and download it from the webservice.
This is what i did for upload (working, but im not sure this is a best way) :
Convert the image to base64 String in android apps
Send that converted string (form image) to the webservice.
Decode that string with base64_decode function in the webservice.
Save the image from the decoded string, using file_put_contents.
Input the decoded string to the BLOB field in my database.
What make me confuse is, if i already saved the image file (step 4), do i still need to save it to the BLOB column (step 5)?
Now, i got confuse with the download part. This is what im planning to do :
Get the image file from step 4 in upload using file_get_contents (return string)
Send the result (string) to my android apps
Get the string and convert it to the image (how?)
Is it all i need to download?
Do i need to use base64_decode or base64_encode in download? When do i use it?
Sorry if my question sounds silly, i still dont get the logic.
Thanks a lot for your time, all help is appreciated.
What make me confuse is, if i already saved the image file (step 4), do i still need to save it to the BLOB column (step 5)?
No you don't. You can store in DB just a reference to that file, like filename or full path.
Now, i got confuse with the download part. This is what im planning to do :
Get the image file from step 4 in upload using file_get_contents (return string)
and base64_encode it
Get the string and convert it to the image (how?)
You need to base64 decode it, because you encode it before sending it from the server. (step 1)

Create Empty CloudBlockBlob in Azure

I'm hoping the answer to this question is quite simple, but I can't get it working after looking at the Azure Java API documentation.
I am trying to create an empty CloudBlockBlob, which will have blocks uploaded to it at a later point. I have successfully uploaded blocks before, when the blob is created upon the first block being uploaded, but I can't seem to get anything other than ("the specified blob does not exist") when I try to create a new blob without any data and then access it. I require this because in my service, a call is first made to create the new blob in Azure, and then later calls are used to upload blocks (at which point a check is made to see if the blob exists). Is it possible to create an empty blob in Azure, and upload data to it later? What have I missed?
I've not worked with Java SDK so I may be wrong but I tried creating an empty blob using C# code (storage client library 2.0) and if I upload an empty input stream an empty blob with zero byte size is created. I did something like the following:
CloudBlockBlob emptyBlob = blobContainer.GetBlockBlobReference("emptyblob.txt");
using (MemoryStream ms = new MemoryStream())
{
emptyBlob.UploadFromStream(ms);//Empty memory stream. Will create an empty blob.
}
I did look at Azure SDK for Java source code on Github here: https://github.com/WindowsAzure/azure-sdk-for-java/blob/master/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlockBlob.java and found this "upload" function where you can specify an input stream. Try it out and see if it works for you.

Android get 1st result and copy from google search(automatic)

I want a code to search to google engine for songs via zippyshare . For example the keyword will be "inna sun is up zippyshare" and the first result is this url www32.zippyshare.com/v/55151563/file.html . i want to retrieve the code 55151563 from the the 1st result of google.
Thank you in advance
I will not write the code for you, but I can tip you to the right approach.
Get the url using String search = "http://www.google.com/search?hl=en&q=" + string_to_search;
Download the webpage using URL, InputStream and OutputStream. Check this post here.
Read the file and find the first instance of zippyshare.
Here you can read about xml parsing

Categories

Resources