Home > Net >  Missing fields in request to upload files to minio using the generated presigned url
Missing fields in request to upload files to minio using the generated presigned url

Time:04-12

I'm using Minio Server to handle files in my nodejs API, basically to emulate s3 locally. I generated Presigned Url to upload images directly.

Presign Url Generation works fine but when I upload my file from Postman the file it gives me this error:

<?xml version="1.0" encoding="UTF-8"?>
<Error>
    <Code>MissingFields</Code>
    <Message>Missing fields in request.</Message>
    <Key>records/marbles.jpg</Key>
    <BucketName>bucket</BucketName>
    <Resource>/bucket/records/marbles.jpg</Resource>
    <RequestId>16E442AB40F8A81F</RequestId>
    <HostId>0149bd16-e056-4def-ba82-2e91346c807c</HostId>
</Error>  

The request seems to contain the required headers enter image description here

the headers are:

enter image description here

and I also select the file properly in postman(Body>binary>select file) :

enter image description here

The code I use for presigned url generation is:

import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
import { PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
const s3Client = new S3Client({
        region: 'us-east-1',
        credentials: {
        accessKeyId: 'minioadmin',
        secretAccessKey: 'minioadmin',
    },
        endpoint: http://172.21.0.2:9000,
        forcePathStyle: true,
    });
  
const bucketParams = {
        Bucket: 'myBucket',
        Key: `marbles.jpg`,
};  
  
const command = new PutObjectCommand(bucketParams);

const signedUrl = await getSignedUrl(s3Client, command, {
        expiresIn: 10000,
})

CodePudding user response:

I was trying and changing ports, and the put command seems to work when I use only local host for url generation

so, in this above:

new S3Client({
        region: 'us-east-1',
        credentials: {
        accessKeyId: 'minioadmin',
        secretAccessKey: 'minioadmin',
    },
        endpoint: http://172.21.0.2:9000,
        forcePathStyle: true,
    });  

I use:

new S3Client({
        region: 'us-east-1',
        credentials: {
        accessKeyId: 'minioadmin',
        secretAccessKey: 'minioadmin',
    },
        endpoint: http://172.21.0.2, // or 127.0.0.1
        forcePathStyle: true,
    });  

Note, I haven't used any port number, so the default is 80

If you're using docker-compose add this config:

. 
.
.
ports:  
  - 80:9000  

and it works fine.

  • Related