|
@@ -92,7 +92,7 @@ namespace iiie.WebApiUtils.BusinessManager
|
92
|
92
|
/// </summary>
|
93
|
93
|
/// <returns>The file path</returns>
|
94
|
94
|
[NonAction]
|
95
|
|
- public async Task<OpResult<string>> SaveFileToTemp()
|
|
95
|
+ public async Task<OpResult<DboUploadFile>> SaveFileToTemp(string name = null)
|
96
|
96
|
{
|
97
|
97
|
IEnumerable<HttpContent> parts = null;
|
98
|
98
|
try
|
|
@@ -102,30 +102,36 @@ namespace iiie.WebApiUtils.BusinessManager
|
102
|
102
|
}
|
103
|
103
|
catch (Exception e)
|
104
|
104
|
{
|
105
|
|
- return OpResult<string>.Error(ResultStatus.InputError, e, "Failed to read post parts (maximum size exceeded?)");
|
|
105
|
+ return OpResult<DboUploadFile>.Error(ResultStatus.InputError, e, "Failed to read post parts (maximum size exceeded?)");
|
106
|
106
|
}
|
107
|
|
- HttpContent file = parts.FirstOrDefault();
|
|
107
|
+ HttpContent file = parts.FirstOrDefault(x => name == null || (x.Headers.ContentDisposition != null && x.Headers.ContentDisposition.Name.Trim('"') == name));
|
108
|
108
|
if (file == null)
|
109
|
109
|
{
|
110
|
|
- return OpResult<string>.Error(ResultStatus.InputError, "No uploaded file", "");
|
|
110
|
+ return OpResult<DboUploadFile>.Error(ResultStatus.InputError, "No uploaded file", "");
|
111
|
111
|
}
|
112
|
112
|
try
|
113
|
113
|
{
|
114
|
|
- var path = Path.GetTempFileName();
|
|
114
|
+ DboUploadFile dbo = new DboUploadFile();
|
|
115
|
+ if (file.Headers.ContentDisposition != null)
|
|
116
|
+ {
|
|
117
|
+ dbo.OriginalFilename = Uri.UnescapeDataString(file.Headers.ContentDisposition.FileName.Trim('"'));
|
|
118
|
+ }
|
|
119
|
+ dbo.TempFilePath = Path.GetTempFileName();
|
115
|
120
|
using (var memoryStream = new MemoryStream(await file.ReadAsByteArrayAsync()))
|
116
|
121
|
{
|
117
|
|
- using (var streamWriter = new FileStream(path, FileMode.OpenOrCreate))
|
|
122
|
+ using (var streamWriter = new FileStream(dbo.TempFilePath, FileMode.OpenOrCreate))
|
118
|
123
|
{
|
119
|
124
|
memoryStream.WriteTo(streamWriter);
|
120
|
125
|
memoryStream.Close();
|
121
|
126
|
streamWriter.Close();
|
122
|
127
|
}
|
123
|
128
|
}
|
124
|
|
- return OpResult<string>.Ok(path);
|
|
129
|
+
|
|
130
|
+ return OpResult<DboUploadFile>.Ok(dbo);
|
125
|
131
|
}
|
126
|
132
|
catch (Exception e)
|
127
|
133
|
{
|
128
|
|
- return OpResult<string>.Error(ResultStatus.InputError, e, "Failed to write uploaded file");
|
|
134
|
+ return OpResult<DboUploadFile>.Error(ResultStatus.InputError, e, "Failed to write uploaded file");
|
129
|
135
|
}
|
130
|
136
|
}
|
131
|
137
|
}
|