You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var customFileName = (modifyName ? (DateTime.UtcNow.ToString("yyyyMMddHHmmss") + "_") : string.Empty) + file.FileName;
// Make a bucket on the server, if not already present.
var beArgs = new BucketExistsArgs()
.WithBucket(_bucket);
bool found = await _minioClient.BucketExistsAsync(beArgs).ConfigureAwait(false);
if (!found)
{
var mbArgs = new MakeBucketArgs()
.WithBucket(_bucket);
await _minioClient.MakeBucketAsync(mbArgs).ConfigureAwait(false);
}
// Upload a file to bucket.
var putObjectArgs = new PutObjectArgs()
.WithBucket(_bucket)
.WithObject(customFileName)
.WithStreamData(file.OpenReadStream())
.WithContentType(file.ContentType)
.WithObjectSize(file.Length);
await _minioClient.PutObjectAsync(putObjectArgs).ConfigureAwait(false);
var createDocument = new CreateDocument()
{
DocumentTypeId = documentTypeId,
Link = customFileName,
Name = file.FileName,
};
var documentId = await _documentRepository.CreateAsync(_mapper.Map<ICreateDocumentDmo>(createDocument))
?? throw new EppsException(TextMessages.FileUploadError);
return (await _documentRepository.GetAsync(documentId)) !;
}`
Which works. And second one, which throws an exception "MinIO API responded with message=The provided 'x-amz-content-sha256' header does not match what was computed."
// Make a bucket on the server, if not already present.
var beArgs = new BucketExistsArgs()
.WithBucket(_bucket);
bool found = await _minioClient.BucketExistsAsync(beArgs).ConfigureAwait(false);
if (!found)
{
var mbArgs = new MakeBucketArgs()
.WithBucket(_bucket);
await _minioClient.MakeBucketAsync(mbArgs).ConfigureAwait(false);
}
// Upload a file to bucket.
using (var streamData = new MemoryStream(data))
{
var putObjectArgs = new PutObjectArgs()
.WithBucket(_bucket)
.WithObject(customFileName)
.WithStreamData(streamData)
.WithContentType(contentType)
.WithObjectSize(data.Length);
await _minioClient.PutObjectAsync(putObjectArgs).ConfigureAwait(false);
}
var createDocument = new CreateDocument()
{
Link = customFileName,
Name = fileName,
};
var documentId = await _documentRepository.CreateAsync(_mapper.Map<ICreateDocumentDmo>(createDocument))
?? throw new EppsException(TextMessages.FileUploadError);
return (await _documentRepository.GetAsync(documentId)) !;
}`
I tried using memory stream, I tried setting Content-Type by hand but nothing works. I am so lost. Does anybody know what is wrong here?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have two rather similar methods:
`
public async Task UploadAsync(IFormFile file, long? documentTypeId, bool modifyName = true)
{
`public async Task UploadAsync(byte[] data, string fileName, string contentType, bool modifyName = true)
{
var customFileName = (modifyName ? (DateTime.UtcNow.ToString("yyyyMMddHHmmss") + "_") : string.Empty) + fileName;
Beta Was this translation helpful? Give feedback.
All reactions