I'm just starting out to use the Parse API and I am going to, among other things, use it to store some static data that my iOS apps will occasionally download. I do, however, have a need to occasionally update this static data, but Parse isn't very clear on how to update that data once it is initially uploaded.
Parse's API docs show you how to upload files of the same name without overwriting existing data, but in this case that's exactly what I want to do. How do I upload updates to the same file?
In this case I am using the REST API to upload the content. I get the URL back to reach the content, but I am not able to update it by simply POSTing to the URL that it returns. I get a 405 denied. I try changing the HTTP method to PUT, but that results in a 403 Unauthorized.
You can upload a new file, then update the Parse object with a reference to the new file. Each file gets its own unique permalink, so they cannot be "updated" with new content.
However you can update any object to point to the new file.
Turns out that you cannot update a static resource, but upload a new one. This turns out to be four API calls:
Upload resource
Get File object
Update pointer
Delete old resource
Then for a client:
Get File object
Download static resource
Related
I hopefully have a simple request but unable to do by myself due Postman's
file support behaviour.
Case:
Lots of people creating simple URLs for a maschine learning tool and pushing them into a database.
The URLs got just simple differencies of an count up ID Number to request the appropriate information.
However, at the end of the day we got lots of simple single textfiles each
with 1 single url line.
What I just wanna do is to push the whole folder into Postman to finally test all created URLs and save the rsult as json...hm
Postman does not support textfiles and yeah thats crackbrained but I dunno how?
Any idea is welcome?
Thanks a lot in advance
brgds
You can export a Postman's Collection and see how the requests in it are exported (The JSON Format of a request is to be noted).
Now you know the format of a request, you can create a script that'll just run through all your files and basically generate a request out of each URL and add that to the exported collection's JSON.
Finally, import the collection back into Postman and you'll have all the requests ready to be tested out.
Context of what I'm trying to accomplish:
User shares a file with the bot
Other users interact with the bot via a dialog
The bot shares the original file to the other users
For example, we want to share a file to the bot that contains this week's cafeteria menu. Each time users would interact with the bot in a certain way, it would share the cafeteria menu with them so that they can consult it.
I've tried calling files.share method but bots can't perform this action (get invalid token type error).
As far as I can tell, there is no way to do this currently. I've tried link unfurling in the message body but that only works if the file itself was already shared to the user. If not, the link simply won't unfurl and clicking it will fail.
The bot can perform a files.upload call and re-upload the contents of the file to each user individually. This seems incredibly wasteful but appears to be the only way to work currently.
Is there something I'm missing?
The reason your bot can not use file.share is that this is an undocumented API method and you need a legacy token to use it. No other token (user token, bot token) will work, because it requires the post scope, which only exists for legacy token.
Approach A: Legacy Token
So one approach would be to use a legacy token with your bot, which you can create here for your current workspace. That should work nicely if your Slack app is only used on your "own" Slack workspace where you can create and use a legacy token.
Approach B: File Mention
Another approach is to use the mention feature in messages to share a file. This works by sending the private link (url_private property) of an already shared file in a message to a new channel. This will automatically re-share the file in that channel. I believe this only works with files that how been previously shares in a public channel and can therefore be re-shared. Be aware though that the file mention feature is currently being reworked, so this behavior might change.
Example:
https://slack.com/api/chat.postMessage?token=TOKEN&channel=CHANNEL&as_user=true&text=URL_PRIVATE
For more details see the Slack tutorial Storing, retrieving, and modifying file uploads.
Approach C: External File / image file
If you host your file externally or create a public URL for a file uploaded to Slack you can share it in every channel by just adding the URL to a message. Slack will automatically unfurl it and therefore share it to the user in any channel. This is different to Approach B, because its not a file mention and requires a public URL. You get the public URL of an uploaded file by calling files.sharedPublicURL.
If i'm not wrong, you can do like this :
you share a file with your bot
you retrieve the file shared ID, so his url_private property (cf https://api.slack.com/types/file#authentication)
you then donwload the file
you can then re-share it several times later (without re-uploading to each user)...
I have a rails-api project, which provide the api to access my data.
I use carrierwave to store my file, my model called User and file attribute called image.
So, the image attribute contained the file_name, url and some other info.
In order to translate the file through the api, I added the gem carrierwave-base64.
I understand the Upload process. The client app encode the file to base64 code, then sent to backend by a json message. For example:
{user: {email: "test#email.com", image: "data:image/jpg;base64,#{base64_image}"}
So when the backend receive the json request, the carrierwave will parse the base64 code to a file and store it to local or S3
What I do not understand, is the Download process:
When I request the user info, what I assume is that the image file would be transfered as a base64 code in a json message, and then the client app will encode the base64 code to a file(image), and then display.
But actually, what I can provide for the json data, is the file url, not the base64 code.
The reason I want to get the file(image) from the api-server is because I don't want to the client app directly access s3 by url. So every time when the client app want to get a file, it will request the api-server, and api-server will get the file and transfer to the client.
Does anyone can explain how to do the download?
Or if I was thought in a wrong strategy, that I need another api endpoint to response a file object, not just accompany with user model.
Cheers.
Restricting Access to Objects Stored on Amazon S3
https://github.com/thoughtbot/paperclip/wiki/Restricting-Access-to-Objects-Stored-on-Amazon-S3
you did a good thing with uploading ,But while downloading you need to send URL no base64 and its traditional
Also for securrity purpose you can put public read permission on s3 while uploading and use expiring_url(60, :thumb) for your clients
In this URL get expired in time that you have specified
I have implemented a RESTful API with few resources, for example:
/products/
/products/1
/products/2
/categories/
/categories/1
/categories/2
etc.
Now, I have been told that the app should mainly work offline, therefore I need to get all the data from the APIs and store it locally.
Since I am not providing a single chunk of data but there are different resources URI that needs to be called in order to get all the data I was wondering if this could be a problem.
How does this work? will there be many HTTP calls or one call will do everything?
What is the best approach in this case?
Are these endpoints in themselves?
/products
/categories
It's a pretty well established convention for those to return the entire collection. You could even add some request parameters for filtering etc.
Each URI represents single peace of data. The main idea of REST, instead of having randomly named setter and getter URLs and using GET for all the getters and POST for all the setters, we try to have the URLs identify resources, and then use the HTTP actions GET, POST, PUT and DELETE to do stuff to them.
So, using AFNetworking, for example, you get all benefits of this architecture.
Download model could look like:
Ask server for specified resource by get request
save response in background thread
ask for new peace of data
Of course, if you do not have ability to make new endpoint, that will download all stub, you must download it separately for each:
/products/
/products/1
/products/2
/categories/
/categories/1
/categories/2
Setting up your endpoints in this way will allow for a user of your app to retrieve a single product/category or a list of products/categories.
Here's what each of these API endpoints should do when they are called.
/products - returns a list of products
/categories - returns a list of categories
/products/:id - returns the product with the specified id
/categories/:id - returns the category with the specific id
As far as allowing the app to work mostly offline. The best approach is to do some caching on the client (app) side. Every time a call is made to one of these endpoints for the first time, the result should be stored somewhere on the client side. The next time that same request is made, the data has already been retrieved previously, so therefore no network call needs to be made and the app will work offline. However, the first call needs to have a network connection to be made.
This can be implemented with a dictionary, where the key is the request (/products, /categories/1, etc.) and the value is the result that is returned from the API request. Every time a request is made, your app should first check if the data exists already on the client side. If it does it does not need to make a network call to get it and can just return the data that's present on the cleint.
I've developed an HTTP API Server (intended to be called by third-party applications, not necessarily by a web browser) which has one universal call to get (download) any and all types of files by passing a name parameter in the query string for the file requested. All calls, no matter for which file, are handled in the same custom request handler of mine called Get (not to be confused with the standard HTTP get). A query string includes a property name which identifies the unique file to get.
So a request may look like:
http://MyServerURL.com/Get?Key=SomeAPIKeyForAuthentication&Name=SomeUniqueIdentifier
First of all, I know I can obviously make the server fetch a file using only the URI, for example...
http://MyServerURL.com/SomeUniqueIdentifier?Key=SomeAPIKeyForAuthentication
...but the design is specifically meant to use this one universal get command, so I need to keep this unique identifier in the query string. The actual applications which connect to this API will never need to know this filename, but there may be an event when a URL is manually provided for someone to open in their browser to download a file.
However, whenever a file is downloaded through a web browser, since the call is get, the saved filename also winds up being just get.
Is there any trick in HTTP which I can implement on my server which will force the downloaded filename to be the unique identifier, rather than just get? For example, some method such as using re-direct?
I'm using Indy 10 TIdHTTPWebBrokerBridge in Delphi XE2 as the web server. I'm looking for a way in this component (technically in its corresponding TWebModule handler) when it handles this get request, to make the response's filename whatever string I want (in this case, SomeUniqueIdentifier). I've heard the term "URL Re-writing" but that's a rather different topic, and don't think it's what I need, yet it might.
That seems to a rather long winded way of saying you want to set the filename for an HTTP download indpendently of the URL used to fetch it. In which case you simply send a Content-Dispositon header specifying the desired filename. See section 19.5.1 of rfc 2616
e.g.
Content-Disposition: attachment; filename="stackoverlow.ans"