Open alexandernst opened 8 months ago
May I ask if there has been any progress here? I have encountered the same issue.
The same error using Bun 1.1.5. The version of @aws-sdk/client-s3
is 3.509.0
.
Same issue for me
Bun 1.1.4
@aws-sdk/client-s3: 3.565.0
My error is always:
FailedToOpenSocket: Was there a typo in the url or port?
Hello,
To leave it as feedback, I made it work by adding the following config to the client constructor:
const s3Client = new S3Client({
endpoint: `xxxx`,
forcePathStyle: true, // This is what made it work.
credentials: {
accessKeyId: 'xxx',
secretAccessKey: 'xxx',
},
});
Credits to this solution: https://medium.com/la-mobilery/short-bun-hono-send-and-get-documents-using-aws-s3-client-fff20d0ba80e
My investigation:
The URL gets correctly generated in NodeJS; therefore, the signature is valid. Something is off with BunJS generating this URL, the signature seems to work properly as with forcePathStyle: true
works. I hope I have helped narrow down the issue.
What worked for me, was to use: @aws-sdk/lib-storage
instead of a manual PutObject
-Command.
I am using a third-party-s3-provider, and not AWS.
import { Upload } from "@aws-sdk/lib-storage";
//....
const fileStream = createReadStream(localFilePath);
const upload = new Upload({
client: this.client,
params: {
Bucket: bucket,
Key: key,
Body: fileStream,
Metadata: {
....
},
},
});
try {
await upload.done();
} catch (e) {
console.error("Error uploading file to S3", e);
throw e;
}
There was also no need for the forcePathStyle: true
-setting.
Got the reference-implementation over at multer-s3
What version of Bun is running?
1.0.7
What platform is your computer?
Darwin 23.0.0 arm64 arm
What steps can reproduce the bug?
Run the following code:
What is the expected behavior?
The file should be uploaded to Cloudflare's R2 (or any other S3-compatible API)
What do you see instead?
Additional information
The same code works fine with Node