SlickUpload Upload to disk

The file upload stream provider is a built-in SlickUpload provider that uses the filesystem for uploaded file storage. Using this provider, SlickUpload can store files to any location your ASP.NET application has access to, including paths inside the application, other paths on the same server, or a seperate server via a UNC path to a file share.

Configuration

To use the file provider, set the type="File" attribute on the uploadStreamProvider web.config key. The following settings allow you to customize the filename and location where the files will be stored:

1
<uploadStreamProvider type="File" />

If you want more control over the storage location, you can inherit from theFileUploadStreamProvider class to create your own custom file based upload stream provider.

Attributes

location – Optional String attribute
Specifies the root storage location. This can be an absolute path (c:folder), an app relative path (~/folder), or a UNC path (\serverfolder).

NOTE: The user ASP.NET is running under (by default ASPNET for XP and IIS_WPG for Windows 2003 and later) must have write access to the specified path.

existingAction – Optional ExistingAction attribute
Specifies the action to take when trying to upload to a file that exists.
Exception
Throw an exception and cancel the upload.
Overwrite
Overwrite the existing file
Rename
Rename the new file using a rename sequence to find the first unused filename. The builtin sequence starts with the desired filename, then iterates a number N starting with 1 and appends [N] to the filename until it finds a free filename.

You can customize the rename sequence by creating a class that inherits fromFileUploadStreamProvider and overriding the GetRenameSequence method, returning a new sequence generator for your desired renaming sequence.

Default: Exception
fileNameMethod – Optional FileNameMethod attribute
Specifies the method to use to generate a filename. Possible values:
Client
Use the client filename as the server filename.
Guid
Use a unique GUID as the server filename.
Default: Client

Controlling the filename during upload

To control the filename used during the upload, you can use one of the three file name generation methods defined above: Client or Guid.

If you want to generate your own filename (including path if you desire), you can create a class that inherits from FileUploadStreamProvider and override the GetServerFileNamemethod. For an example of this, look at the CustomFileName sample. You can also override other methods of the FileUploadStreamProvider class to do more customization, such as a custom rename sequence.

Retrieving the server filename

After the upload you can get the server filename a file was written using theUploadedFile.ServerLocation property.

原文地址:https://www.cnblogs.com/8090sns/p/3311381.html