POST method WEBDAV not run - http

I had a server install WEBDAV and I try to do any WEBDAV method
all method like copy, delete, get, lock, mkcol, propfind, propatch run good.
I can create file and store data in server with PUT method. But I don't know how to do it in POST.
when I post anydata to exist file server return data of old file.
And I check in server this file not change any thing
when I try to post new file it return "The requested URL - URL of
file - was not found on this server."
when I try to post new file with out full path, I just send to
folder where I want to store file. I hope server create file with
auto gen Name of file and return name for me. But server return the
resource content in folder ( some thing like index.html )
I want to know how to implement POST method, it can create or repair file on WEBDAV server. any one can help me ?

In general, WebDAV servers do not support POST (more precisely: the WEBDAV specification doesn't mandate any specific behavior for POST, so servers vary in what they do).

Related

How to implement a rename function for a HTTP based file server?

I have to implement a HTTP server with some file server capabilities.
I'd already coded HTTP HEAD, GET, PUT, and DELETE requests.
Next thing I need to implement something like RENAME or MOVE to change the name of a file which is already stored on the server. But I cannot find an appropriate HTTP request method for this.
Any idea how to do this or might that be not possible?
Found WebDAV extensions which added a matching HTTP method MOVE for this.
https://tech.yandex.com/disk/doc/dg/reference/move-docpage
http://www.qed42.com/blog/using-curl-commands-webdav
There is also a method MKCOL to create a directory.

Why does a directory exist and not exist on a web server simultaneously?

While I'm sure the title could be improved for clarity, my meaning is thus:
When fetching a URL for a file download at http://example.com/dir1/dir2/file.zip, the response code is 200, yet attempting to access http://example.com/dir1, or http://example.com/dir1/dir2, elicits a 404 response code.
Why is this?
URLs don't necessarily correspond to actual directories on the server. Ultimately the path component of a URL is just a name; the server can translate that name to whatever it wants on the back end.
In this case it seems likely that /dir1/dir2/ is a directory on the server, but even so that doesn't mean anything. The server knows about a resource named /dir1/dir2/file.zip, but doesn't know anything about a resource named /dir1.

What status code to use when certifying an upload?

I'm working on a direct-to-S3 upload service that operates in two parts described below. This service would not be used by browsers, but would be a RESTful API used by other software clients.
Make a request to an endpoint which certifies and validates the upload, returning an upload URL if all's well.
Make a PUT request to the URL returned from #1 to actually do the upload to S3.
How should the server structure the response for the first endpoint?
The first option I am considering would be to use GET and return a status code 302 with a Content-Location header containing the URL to upload to. However, the intent behind the redirect descriptions in the spec seems to be focussed on redirecting after a form submission.
The other option I'm considering is to use POST for the first endpoint and returning a Location header with the URL, as described here:
If a resource has been created on the origin server, the response
SHOULD be 201 (Created) and contain an entity which describes the
status of the request and refers to the new resource, and a Location
header. RFC 2616 #9.5
Please advise on what other people have used in such circumstances?
I think it mainly depends on whether your API itself will have a resource referencing the uploaded file or not. The only one with knowledge of the uploaded file is the S3 itself or your API has something referencing it?
If the first case where only S3 knows about it, then it's OK to use the GET if it acts merely as a generator for the upload parameters, including the URI.
If the second case, then it shouldn't be a GET, since you're changing something on your side. Yes, you should make a POST, but the Location header should be used to return the URI for the created resource that references the uploaded file. That resource may have the upload URI and it could act like a state-machine, tracking if the file is uploaded or not. To avoid the need for clients to GET that resource before being able to upload, you may return the upload URI in the Link header, with a rel reflecting that purpose.

HTTP PUT for new file creation and directory creation

How would a HTTP Server differentiate whether the request in PUT is for a folder creation or a file creation in a directory.
For HTTP GET what I understood is, if the URL has a trailing /, then HTTP Server looks out for a folder with that name and, if does not exist can look out for a file.
How does this work for PUT for a new file and folder creation?
HTTP (the protocol) doesn't have any concept of files or folders. URIs are opaque, except when a relative URI reference is resolved against a base URI.
If you want your server to provide file/folder services, you may want to look into WebDAV (RFC 4918).

Get http url path of local file on server in asp.net

I'm using ASP.NET with MVC 2 and have trouble translating a local file url to a server address. It would seem like a fairly simple and common task, but google searches gives me no good answers. (Perhaps i suck at searching)
I have a controller that takes a file from a html form in a view and saves it to disk. I need to return the real url of this file back to the View. Whatever method i use, I always get a string with the local path of the file instead of the http path.
I suspect the url might get translated to http address once the project has been deployed, but I really need the server address when debugging without having to hardcode anything.
Consider the following example in some controller method:
string url = Url.RequestContext.HttpContext.Server.MapPath("~/Content/Files/" + Path.GetFileName(file.FileName));
// outputs: "C:\\Users\\xxx\\Documents\\Visual Studio 2010\\Projects\\[ProjectName]\\Content\\Files\\file.png"
// whereas i'd like something like "http://localhost/Content/Files/file.png" instead
any ideas?
It depends on where you are storing this file. If you are storing it in a directory which is outside of the virtual directory root you won't be able to access it. If the file is inside a folder which is accessible over HTTP you could simply use the Content method:
string url = Url.Content("~/Content/Files/foo.txt");

Resources