这里我一次只能选择一张图片。但我想选择多张图片。有人请帮助我。如果我正在选择多个图像,它只保存一个图像。我正在使用邮递员服务选择图像。
public ServiceResponse<string> UploadDoc(Stream fileContents)
{
IncomingWebRequestContext woc = WebOperationContext.Current.IncomingRequest;
string fileName = woc.Headers["fileName"];
if (fileName.Length <= 0)
{
throw new Exception("File not attached");
}
if (fileName == "")
{
throw new Exception("Please send fileName in header");
}
//string userId = woc.Headers["UserAuthor"];
string fileNameUnique = Guid.NewGuid() + fileName;
string upload_FilePath = @"" + docFolder + "\\" + fileNameUnique;
string fileUrl = hostUrl + "/Document/" + fileNameUnique;
try
{
int length = 0;
using (FileStream writer = new FileStream(upload_FilePath, FileMode.Create))
{
int readCount;
var buffer = new byte[8192];
while ((readCount = fileContents.Read(buffer, 0, buffer.Length)) != 0)
{
writer.Write(buffer, 0, readCount);
length += readCount;
}
}
var response = new ServiceResponse<string>
{
ResponseObject = fileUrl
};
return response;
}
catch (Exception e)
{
var response = new ServiceResponse<string>
{
IsError = true,
ExceptionObject = new ExceptionModel()
{
ErrorMessage = e.Message,
Source = e.Source,
Severity = 0,
KeyParameter = new[] { "ServiceError" }
}
};
return response;
}
}
答案 0 :(得分:0)
如果我理解你的问题,你可以尝试将Stream参数更改为这样的类。
public class FilesRequest
{
public ICollection<Stream> MyStreams { get; set; }
}
public ServiceResponse<string> UploadDoc(FilesRequest request)
{
// Process the collection in your input, request.MyStreams
}