Downloading images directly from Parse.com, as opposed to using their API - ios

I noticed that for a PFFile type Object stored on my Parse.com developer account, the link is open and accessible for anyone to view/download.
Example a PFFile Object that is named, name.jpg, representing an image could be a URL like :
http://files.parsetfss.com/<some garbled class UUID>/<some garbled image uuid>-name.jpg
Where <some garbled class UUID> appears to be the same for all name.jpg, stored on a class
and <some garbled image uuid>-name.jpg appears to be unique uuid's appended with the actual object name which is 'name.jpg'
Using the above URL, anyone/any client can download the object
So I have some questions regarding this:
Is this normal? Is this by design?
Will the URL for an object change, if nothing else changes?
Am I being unwise in using this information to download images directly, thereby saving the cost of one API call from Parse (although I think I'll make one API call anyways to get the URL) ?
Will downloading directly from this URL, perform better/acceptable compared to downloading via Parse.com API

Yes it's normal. Protection is via the object, don't give access to anyone who shouldn't have it.
No the URL shouldn't change, though strictly you should query from the file object each time you want it to be sure.
You should care more about network calls that API calls in general. You could use cloud code to aggregate responses, or batch requests, but that doesn't reduce API calls.
The download is unchanged as you're always downloading the same file from the same link no matter which API you use to do it.

Related

URLSession: Any way to read a file as it is being downloaded?

The use-case is that I want the user to be able to preview a song hosted at a remote URL. Fine, you say, just use AVPlayer. Yes, but I want to be able to cache the file locally if it is completely downloaded in the course of being previewed. As far as I can tell, there's no way to access the local data that AVPlayer downloads for its streaming playback. Likewise, there's no way to get access to the data being downloaded by URLSession until it is completely downloaded. So, I'd like to find a result using one of these approaches:
Access the data in AVPlayer once it has completed downloading it and save to a file.
Download the data progressively to the cached URL and have AVPlayer play it as enough data becomes available.
Are either of these scenarios possible? Is there some other scenario which will achieve what I am looking to do?
So the solution to this came from the AlamoFire source code. If you use a URLSessionDataTask in the traditional, non-combine way and have a controller conforming to URLSessionDataDelegate, then you can implement the urlSession(_:dataTask:didReceive:) protocol method to receive the data as it arrives, rather than waiting to receive it at completion. This allows you to directly write the data to a file of your choosing that is completely under your app's control.

GetStream feeds without enrichment

Because of some requirements, we don't want to use the enrichment system where stream gets from its own collection the data objects.
In fact, we want to do it as the backend would do, using our own database, but directly from the client (because we don't use any database)
However, when retrieving the activities, we get the following: (iOS)
JSON decoding error: The data couldn’t be read because it isn’t in the correct format..
We create activities in the way that, actor is User:UserID, Object is Object:PostID, Verb:ActionEnum.
That's all we do.. but one more time, we are facing issues on iOS SDK..
Why?
To anyone having this issue, it was coming from the iOS SDK itself... It turned out that, using the REST API from our client solved the issue, but we had to use the "extra" field part of Go to deliver our required data :)
Hope it helps

Google Drive API v3 for iOS : How to get thumbnails?

In the past, with Google Drive API v2, I could easily get thumbnails for pictures or videos with the property thumbnailLink on GTLDriveFile.
But now, with the API v3 which I currently use with Swift, the thumbnailLink of the files I get from Google Drive is nil, so what can I do to get thumbnails of images and videos stored in the user's Google Drive. I need to display theses in my iOS app.
Make sure to specify thumbnailLink in fields, such as
let query = GTLQueryDrive.queryForFilesList()
query.fields = "files(id, name, thumbnailLink)"
then you can access the property thumbnailLink for images and videos
You'd have to use the Drive REST API method Files: get. The result of that method contains thumbnailLink but according to the documentation it is 'a short-lived link to the file's thumbnail. Typically lasts on the order of hours.
Alternatively, you can cache the thumbnail in your application, reducing the count of drive api requests and thus improve your page performance. You need to fetch the information for the uploaded file. The easiest way of caching is to simply download the thumbnail and save it like fileid_thumb somewhere and upon the next request, you check if such a file exists before actually requesting the thumbnail. Check here the detailed explanation.
You can also upload a thumbnail by setting the contentHints.thumbnail property on the File resource during an insert or update call as follows:
Set contentHints.thumbnail.image to the URL-safe Base64-encoded image (see RFC 4648 section 5)
Set contentHints.thumbnail.mimeType to the appropriate type for the image format
You can also check the accepted answer in this SO question.
Hope this helps!

Generate file-directory-safe string using URL?

My app is sent messages which sometimes include http links to images. When this happens, I want to cache the image locally, so I can display the image in future without needing to download it, if it exists locally.
But lets say the image url is http://imgur.com/abcdef.jpg. A file path of something like this, I'd imagine could have all sorts of issues:
/var/Applications/[application]/documents/http://imgur.com/abcdef.jpg
What I need is a way to take the given image URL and generate a file directory-friendly string, so that I can save the image using that URL every time, or check for its existence.
While there are many ways how to implement it (simpliest way would be to create MD5 of the web address, store image as [md5name.png] and then just try to check if md5 file reference exists), I suggest you use one of two libraries made for that:
https://github.com/Haneke/Haneke
https://github.com/rs/SDWebImage
They both work on url-based principles, provide you with all known implementations of caching and they handle cases like this by default. Both of them also download images in background which is recommended way to do it and have convenience methods to load images in UIImageView.
Hope it helps!

How would you upload an image URL to an external website which generates a new URL for it and retrieve the newly generated url in rails?

I am creating a website which allows users to post links to gif images stored externally. Unfortunately gifs are terribly expensive and luckily I have found the following website which compresses them quite radically: http://gfycat.com/
Currently my app stores the url to the linked image (as of yet it is uncompressed and without the use of gfycat)
What I would like to do is to take the url that the user posts, use it to compress the gif via gfycat.com and then store the newly generated url (pointing to the compressed image) in my database.
How would I do this?
Sorry for the long explanation btw
Just took a look at gfycat.com, seems like they do have an accessible webservice at http://gfycat.com/fetch/:url
If this is the case, and you already have the URL you can very easily grab the 'minified' version of the gif by grabbing the URL and saving the file.
So, I would probably do something like this:
Install carrierwave or another image upload gem of your choice
In the case you used the above gem...
assuming Cat is your model, and you have an uploader attached to it named gif_photo, and also assuming the original 'gif' url is stored as original_gif_url
You can do something like the following (assuming #cat is some instance of the cat model):
#cat.update_attribute(:remote_gif_photo_url, "http://gfycat.com/fetch/#{#cat.original_gif_url}")
as simple as that :)... to get back at the gif, you can simply call #cat.gif_photo_url
(again, assumptions for code above are using carrierwave syntax, but can easily be done with any of its alternatives.)

Resources