I have encountered a strange problem I am unable to debug. An image is uploaded to Onedrive via some code very similar to the given example, and once uploaded, the image is visible in the OneDrive web interface.
http://msdn.microsoft.com/en-us/library/dn659727.aspx
Upon trying to download it, again using code from the example, the following line of code
Bitmap bMap = BitmapFactory.decodeStream(input);
also returns a null value for bMap. I know these files (which I obtain from copying from the Android Clipboard and writing to a file on disk) are valid, b/c I use them in Gridview elements and upload/download them to Dropbox in a similar way.
Is there some kind of jpg re-encoding performed in OneDrive (like RGB->CKMY conversion) what would no longer prevent them from working?
Also, is there some other type of query parameter like "/picture?type=thumbnail" or "/picture?type=normal" that needs to be appended to a file.XXXX OneDrive ID that would prevent any possible conversion?
Is there a way to debug exactly why the BitmapFactory.decodeStream() function fails, like debugging output?
EDIT: So, I came across the following SO post, and figured out this is the same problem I am having.
OneDrive - Wrong size for PNG files
For a certain file, if I download it using the Onedrive SDK and look at the stream length
public void onDownloadCompleted(LiveDownloadOperation operation) {
int length = operation.getContentLength();
}
it reports a size of 2723 bytes, but if I download the file and save it using a desktop web browser, the file is 1837 bytes. Is there something I am missing about reading the size of a stream, or is the API just broken?
This is documented behaviour as per http://msdn.microsoft.com/en-us/library/dn659726.aspx (see the first note under uploading).
You can disable conversion by adding downsize_photo_uploads=false to your query string.
The answer to this question apparently is, there is a bug in the Onedrive SDK. I ended up filing an issue on Github with Microsoft, and it turns out they discovered that with certain types of small images (and potentially PDFs), the actually file size being transmitted back after a download is wrong.
https://github.com/liveservices/LiveSDK-for-Android/issues/37#issuecomment-65457177
It's all just a weird artifact of the way I was testing my app. Since Chrome for Android is the only app I've discovered that lets you copy an image to the clipboard, I was just Google search to find images (tiny thumbnail images in the basic web search results), and copying those to the clipboard. Had I been using larger images, I may never have run across this bug.
Related
When I visit a website (containing some text and a few images), the cache directory in /data/data/com.mayexample/app_webview/Cache gets filled with a few files called 4f42185de3a3a461_0, 4f42185de3a3a461_1,et4f42185de3a3a461_2 etc.
I can't do anything with the cache's files.
Do you know a way to open webview cache files? Doesn't one file represent a corresponding cached image for example?
Thanks!
As far as I know the Browser engine (actually the HTTP module) maintains such cached files in a URL-to-HashKey manner. So what you found (such as "4f42185de3a3a461_1") may be associated with any web resource files such as JS/CSS/images/HTML, etc.
I remember WebView used to store such URL-to-HashKey mapping data in sqlite3 tables in earlier Android versions.
The problem here is you have no idea about the mapping relations so you can hardly retrieve the file you want. A tricky way is to read the AOSP source code then you may be able to know how the generate the HashKey by an unique URL, or you can manipulate the sqlite3 tables, if there are still any on Android 4.4.
In my app, I am exporting images with annotations. Because preparing all the images to be exported in advance would be too inefficient, I am rendering the images to be exported on the fly during the export. I do this with a custom ContentProvider for which the URI encodes the rendering parameters. The actual rendering is then done in ContentProvider.openFile(). This all works nicely.
However, I also have to provide results for the MediaStore MediaColumns in the query() method. But since the final image is not rendered yet, I do not know the SIZE of the data.
Searching for a solution, I came across this code:
http://code.google.com/p/openintents/source/browse/trunk/filemanager/FileManager/src/org/openintents/filemanager/FileManagerProvider.java?r=3267
which says in line 121 that for unknown sizes, we should return 'null' "according to the Android docs". But I cannot find this statement in any Android docs. Is this really the way to handle it? In fact, it works nicely with most apps I tried (e.g. GMail), but some simply show a zero file size (like AquaMail).
So, is returning 'null' for unknown file sizes in MediaStore.MediaColumns.SIZE the correct way to handle this?
And if yes, where is this documented?
I've not been successful in searching for this answer, but basically, how can I find the image file name from a website that blocks saving of the images? Normally, the url source will have the image filename and it is easily searchable.
However, some sites lets you hover over the picture and it then zooms to a larger image. The source shows,
for example,
http://example.com/pictures.aspx?ImagePath=ABCDEFGHIJ1234567989KLMNOPQRST==.....
E.g.: A random long string of code, but no .jpg or .png indicating the file name. When right clicking to save, it shows the image is blocked.
How can I get the images using Android code?
Tks
If it's not allowing them to be taken from a website, then it probably shouldn't be taken. That being said, there are a couple of options if you are the owner of the website.
If they are in a database then you can get the url address of them. Also, right clicking anywhere on the page to "View source" should get you some sort of URL of the image.
This seems more of a web service implementation issue rather than anything andriod specific. Many websites have this feature where you are not meant to retrieve information from the url.
However there should be a corresponding supported web service interface for fetching the metadata of a particular resource. If this is not supported then it's meant to be blocked.
The other trial and error sort of way is to invoke a 3rd party API like oEmbed (or Embed.ly : http://embed.ly/) that would return the metadata of the resource for which you have the URL. These services cover a wide range of websites and their resources.
You can search around in their site or find similar such services that would get you this information. Embed.ly is more of a personal preference due to its exhaustive list of supported sites.
I am developing an Android app that uploads image (jpg) to AWS S3. The image is being uploaded but I am unable to open it using web browser: the image is either invalid or opened as a string.
//skipping error handling for simplicity
InputStream is = Utils.streamFromUri(this, uri);
byte[] buffer = new byte[FileUtils.getInputSize(is)];
...
//is is restored at this point
is.read(buffer);
String data = new String(buffer);
S3.createObjectForBucket(bucketName, objectName, data)
Can you please share a working code for upload or give some directions on how to resolve this?
Thanks
First file is just 0 filled. Second file is not a jpeg but appears to be a result of some kind of transformation (there is some photo data in it). There should be no issue with upload under normal circumstances. If you provide specifics on how you uploaded them (code or tool) we can go from there.
Update
Your code to get data for upload is probably not going to work. I don't know specifics about your utilities but when you do
FileUtils.getInputSize(is)
it probably reads the entire stream, so you end up at the end of it and read nothing for upload. I highly recommend that you use Apache Commons IO to read data. And you can get size of it after it's read into memory.
Update 2
You are using byte to string conversion. From String(byte[]) documentation
Constructs a new String by decoding the specified array of bytes using
the platform's default charset.
Since you use binary data, it's getting transformed. That actually also can be seen from your second file which start with ef bf bd which is Unicode replacement character. So refrain from using string for storing binary data.
Two things.
In amazone S3. You need to set the privileges on the image to Everyone: read. I am using Firefox Plugin S3FOX, and then you right click, press Edit ACL and give everyone Read acces.
You might have to set a custome header. Content-Type: image/jpeg
This depends a bit on how you upload the file, normaly this is handeled by automagic.
The files you linked is ruined. Try a different tool to upload the images to S3 if you know the images is good on your computer.
http://www.s3fox.net/
I am managing a bunch of PDF files in an android application maintaining a list of records in a SQLite database as well as storing the pdf files on the external storage.
Now I would like to present a thumbnail of the first page of the pdf in my list view as part of each cell representing a pdf.
I am aware of libraries like iText, fop.. on the JavaSE side that can render a PDF but I would rather not delve into embedding a large library like that. On a similar approach I would also rather not embed a native PDF viewer like droidreader, apv or vudroid.
Otherwise I could of course also get it rendered on a server via some webservice but that is a lot of headache as well.
I am already using intents to get the pdf's displayed for the user so I was thinking it would be great if I could get a thumbnail via a intent call as a result somehow. However I found nothing on the web (e.g. on openintents) that indicates something like that exists ..
So I am a bit at a loss on what to do? What do you think is the best approach to get these thumbnails into my app? Are there any public intents available? Or did I just totally miss something and the SDK provides features for that already (it should imho but currently does not)?
You are going to get a lot faster resopnse rasterizing the PDFs on the server and there are lots of libraries to do this in C, Java, Php.