REST design for file uploads [closed] - rest

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I want to create a REST API for a file upload service that allows a user to:
Open a session
Upload a bunch of files
Close the session
And then later, come back and do things with the files they uploaded in a previous session.
To facilitate dealing with data about each file and dealing with the content of the file itself, this is the URI scheme I am thinking of using:
/sessions/
/sessions/3
/sessions/3/files
/sessions/3/files/5
/sessions/3/file/5/content
/sessions/3/file/5/metadata
This will allow the file metadata to be dealt with separately from the file content. In this case, only a GET is allowed on the file content and file metadata, and to update either one, a new file has to be PUT.
Does this make sense? If not, why and how could it be better?

Why do you need sessions? Is it for Authentication and Authorization reasons? If so I would use http basic with SSL or digest. As such there is no start or end session, because http is stateless and security headers are sent on each request.
Suggestion of upload resource would be to directly map as private filesystem
# returns all files and subdirs of root dir
GET /{userId}/files
GET /{userId}/files/file1
GET /{userId}/files/dir1
# create or update file
PUT /{userId}/files/file2
When uploading file content you then would use multipart content type.
Revised answer after comment
I would design your wanted separation of file-content and payload by introducing link (to file-content) inside upload payload. It eases resource structure.
Representation 'upload' resource:
{
"upload-content" : "http://storage.org/2a34cafa" ,
"metadata" : "{ .... }"
}
Resource actions:
# upload file resource
POST /files
-> HTTP 201 CREATED
-> target location is shown by HTTP header 'Location: /files/2a34cafa
# /uploads as naming feels a bit more natural as /files
POST /sessions/{sessionId}/uploads
-> HTTP 201 CREATED
-> HTTP header: 'Location: /sessions/{sessionId}/uploads/1
-> also returning payload
# Updating upload (like metadata)
/PUT/sessions/{sessionId}/uploads/1

Related

REST server file browser with resume capability

I want to develop a REST server file manager with resume capability using .Net Core WebApi. Currently I have:
GET api/FileManager/path/to/directory: returns JSON with the content of the directory (subdirectories and files)
GET api/FileManager/path/to/file.txt: download the file with resume capability (e.g. Range: Bytes=0-1023)
HEAD api/FileManager/path/to/file/or/directory: returns empty 200 if the file or directory exists, if not returns empty 404
PUT api/FileManager/path/to/file.txt (with the file content in the body): upload a file
DELETE: delete a file or directory if it exists
Now I am struggling with other functions such as rename or compress
My questions:
How can I implement "rename" (which includes the Move case) a file or directory function with REST? Is it PUT or PATCH? I am thinking that the input would have to contain the new full name of the file/directory
How can I implement "compress"? The client will send a JSON body containing the files and directories to be added to the ZIP file. None of the VERBS sounds suitable, for example, if I use POST, will not be able to differentiate with the file upload
Am I missing anything in implementing file download with resume? I heard about bytes=0-0,-1 but have no idea about it.

Are local robots.txt files read by Facebook and Google? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
I have a folder which is half public: The URL is not linked, the people that know the URL are only a few friends (which will not link it) and it is cryptic enough to make sure that nobody lands there by accident.
However, the link is send via Googlemail and Facebook messages. Is there a way to tell Facebook and Google in a local robots.txt file not to index the page?
When I add it to the "global" robots.txt file then everybody who takes a look there will see that in my /secret-folder-12argoe22v4 might be something interesting. So I will not do that. But will Facebook / Google look at /secret-folder-12argoe22v4/robots.txt?
The content would be
User-agent: *
Disallow: .
or
User-agent: *
Disallow: /secret-folder-12argoe22v4/
As CBroe mentioned, a robots.txt file must always be at the top level of the site. If you put it in a subdirecory, it will be ignored. One way you can block a directory without publicly revealing its full name is to block just part of it, like this:
User-agent: *
Disallow: /secret
This will block any URL that starts with "/secret", including "/secret-folder-12argoe22v4/".
I should point out that the above is not a 100% reliable way to keep the files out of the search engines. It will keep the search engines from directly crawling the directory, but they can still show it in search results if some other site links to it. You may consider using robots meta tags instead, but even this won't prevent someone from directly following an off-site link. The only really reliable way to keep a directory private is to put it behind a password.

Wget downloading incomplete file from a URL [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I want to get a file downloaded on my linux system whose url is
http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jre-7u51-linux-i586.tar.gz
and I am issuing the following command as :
wget -U 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:16.0) Gecko/20100101 Firefox/16.0' http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jre-7u51-linux-i586.tar.gz
whereas the user agent is being passed to -U which i have copied from my browser's user agent. But it downloads the file only of size 5.3KB whereas entire file is 46.09MB and the downloaded file is corrupted.
How can I resolve this issue?
Looking at the output, you will realize that oracle denied the request, containing following message:
In order to download products from Oracle Technology Network you must
agree to the OTN license terms.
Be sure that...
Your browser has "cookies" and JavaScript enabled.
You clicked on "Accept License" for the product you wish to download.
You attempt the download within 30 minutes of accepting the license.
Most probably you have to send some GET or POST value and/or keep session data.
The file isn't 'corrupt' exactly; if you go to that URL in a new browser session you'll see an error page saying 'In order to download products from Oracle Technology Network you must agree to the OTN license terms.'. That is the page you've downloaded - the file size of the page it redirects to is 5307 bytes.
Before you can get the file from the download page you have to accept the license agreement using the radio buttons. Doing so creates a cookie in your browser, and when you get the actual file that cookie is checked. wget doesn't have that cookie available.
You need to download directly from the site, or arrange for wget to send a fake cookie, which probably isn't supported in general. Some downloads used to have a wget script attached, not sure if this one does; it doesn't look like it from what's on the download page.

Perl, Template-Toolkit and SEO [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I'm not sure how to deploy best practice for SEO in a new project.
I'm building a CMS that will be used by a group of writers to post news articles to a website. I'm developing the site using Perl and Template-Toolkit (TT2). I've also embedded an open source editor (TinyMCE) in the system that will be used for content creation.
I was planning to save the news article content to the DB as text - though I could also save it to flat files and then save the corresponding file paths to the DB.
From an SEO standpoint, I think it would be very helpful if this content could be exposed to search engines. There will be lots of links and images that could help to improve rankings.
If I put this content in the DB, it won't be discoverable ... right?
If I save this content in template files (content.tt) will the .tt files be recognized by search engines?
Note that the template files (.tt) will be displayed as content via a TT2 wrapper.
I'm also planning to generate a Google XML Sitemap using the Sitemap 0.90 standard. Perhaps this is suffiecient? Or should I try to make the actual content discoverable?
Thanks ... just not sure how the google dance deals with .tt files and such.
If I put this content in the DB, it won't be discoverable ... right?
The database is part of your backend. Google cares about what you expose to the front end.
If I save this content in template files (content.tt) will the .tt files be recognized by search engines?
Your template files are also part of your backend.
Note that the template files (.tt) will be displayed as content via a TT2 wrapper.
The wrapper takes the template files and the data in the database and produces HTML pages. The HTML pages are what Google sees.
Link to those pages.
just not sure how the google dance deals with .tt files and such
Google doesn't care at all about .tt files and the like. Google cares about URLs and the resources that they represent.
When Google is given the URL of the front page of your site, it will visit that URL. Your site will respond to that request by generating the front page, presumably in HTML. Google will then parse that HTML and extract any URLs it finds. It will then visit all of those URLs and the process will repeat. Many times.
The back-end technologies don't matter at all. What matters is that your site is made up of well-constructed HTML pages with meaningful links between them.

How to implement an ePub reader for an iPad/iPhone app [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
I want to implement an ePub reader for the iOS platform. Please suggest any open source code for book flipping animation, bookmarks, font-size customization and single page view (without scroll bars).
As the previous article points out, there is no API that given an ePub will just display it -- you need to do some work:
Unzip the ePub
Read the manifest file and metadata file to find the xhtml documents to display
Load the xhtml documents into a UIWebView using a file:/// URL to the unzipped document
If you want to ensure that the documents don't hit the network you'll need to implement a custom NSURLProtocol and serve the bytes for the files yourself as file:/// allows cross domain access.
That will display the content just fine, but the "hard" part is moving between the documents (which usually represent a whole chapter). This is the work that iBooks and other apps do for you.
NOTE: For the UIWebView to display the content correctly, you have to ensure that the file has a .xhtml extension when using file:/// urls. If you implement your own URL protocol handler, you need to make sure the protocol handler returns the correct xml content type for xhtml, namely:
application/xhtml+xml
Use the ePub packaging format and an open-source reader for reference:
ePub3 Packaging
fbReader Source
Readium Source
Calibre Source
Try this steps :
Source code: AePubReader
Implementation:
Step 1: Create a view with a UIWebView
Step 2: Download an EPUB file and import into your project
Step 3: Unzip EPUB file to a subdirectory in your app's documents folder.
Step 4: Parse the XML file from directory META-INF/container.xml. If this file directory doesn't exist means, your EPUB file is invalid.
Step 5: In this XML, find the first "rootfile" with media-type application/oebps-package+xml. This is the OPF file for the book.
Step 6: Parse the OPF file (also XML)
Step 7: Now you need to know what the first chapter of the book is.
Each in the element has an id and an href. Store these in an NSDictionary where the key is the id and the object is the href.
Look at the first in the . It has an idref attribute which corresponds to one of the ids in (Step 7a). Look up that id in the NSDictionary and you'll get an href.
this is the the file of the first chapter to show the user. Work out what the full path is (hint: it's wherever you unzipped the zip file to in (Step 3), plus the base NSDictionary of the OPF file in (Step 6).
Step 8: Create an NSURL using fileURLWithPath:, where the path is the full path from (Step 7c). Load this request using the UIWebView you created in (Step 1).
Step 9: You'll need to implement forward / backward buttons or swipes or something so that users can move from one chapter to another. Use the to work out which file to show next. Then the XML are in the order they should appear to the reader.
These step got referred from this link
Use UITextView with pageview controller . (Specify your doubts , if any)