-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #981 from riganti/async-file-storage
IUploadedFileStorage and IReturnedFileStorage made async and moved to DotVVM.Core
- Loading branch information
Showing
18 changed files
with
120 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
|
||
namespace DotVVM.Core.Storage | ||
{ | ||
public interface IUploadedFileStorage | ||
{ | ||
/// <summary> | ||
/// Stores uploaded file and returns its unique ID. | ||
/// </summary> | ||
Task<Guid> StoreFileAsync(Stream stream); | ||
|
||
/// <summary> | ||
/// Deletes the uploaded file with the specified ID. | ||
/// </summary> | ||
Task DeleteFileAsync(Guid fileId); | ||
|
||
/// <summary> | ||
/// Gets the stream of the file with the specified ID. | ||
/// </summary> | ||
Task<Stream> GetFileAsync(Guid fileId); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace DotVVM.Core.Storage | ||
{ | ||
public class ReturnedFile | ||
{ | ||
|
||
public Stream Stream { get; } | ||
public ReturnedFileMetadata Metadata { get; } | ||
|
||
public ReturnedFile(Stream stream, ReturnedFileMetadata metadata) | ||
{ | ||
Stream = stream; | ||
Metadata = metadata; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace DotVVM.Core.Storage | ||
{ | ||
public class ReturnedFileMetadata | ||
{ | ||
public string? FileName { get; set; } | ||
public string? MimeType { get; set; } | ||
public Dictionary<string, string[]> AdditionalHeaders { get; set; } = new Dictionary<string, string[]>(); | ||
public string? AttachmentDispositionType { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 6 additions & 5 deletions
11
.../Storage/UploadedFileStorageExtensions.cs → .../Storage/UploadedFileStorageExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,23 @@ | ||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
|
||
namespace DotVVM.Framework.Storage | ||
namespace DotVVM.Core.Storage | ||
{ | ||
public static class UploadedFileStorageExtensions | ||
{ | ||
/// <summary> | ||
/// Saves an uploaded file with the specified ID to the given location. | ||
/// </summary> | ||
public static void SaveAs(this IUploadedFileStorage storage, Guid fileId, string path) | ||
public static async Task SaveAsAsync(this IUploadedFileStorage storage, Guid fileId, string path) | ||
{ | ||
using (var stream = storage.GetFile(fileId)) | ||
using (var stream = await storage.GetFileAsync(fileId)) | ||
{ | ||
using (var fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write)) | ||
{ | ||
stream.CopyTo(fs); | ||
await stream.CopyToAsync(fs); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
4 changes: 3 additions & 1 deletion
4
src/DotVVM.Framework/Utils/TextUtils.cs → src/DotVVM.Core/Utils/TextUtils.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/DotVVM.Framework/DependencyInjection/DotvvmBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.