wpnpeiris / nats-gateway

S3 API compatible NATS Object Store
10 stars 2 forks source link

HTTP endpoint for file upload / download and changs #3

Open gedw99 opened 2 months ago

gedw99 commented 2 months ago

this is really cool. Been meaning to make something like this.

Would like to add a HTTP endpoint to this thats not S3. It can then cal the S3 Api if we want.

For file up and down.

then a very simple golang template html for Files up and down via the HTTP gateway.

wpnpeiris commented 1 month ago

Supporting S3 protocol means having a HTTP endpoint. Basically, the followings are identical:

aws s3 cp file1.txt s3://bucketA --endpoint-url http://localhost:5222
curl --location --request PUT 'http://localhost:5222/bucketA/file1.txt' \
--header 'Authorization: [auth header adhere to s3 protocol]'
--header 'Content-Type: application/json' \
--data 'fie content'

In the second case, Autherization header should be according the S3 protocol.

Or do you mean having another HTTP endpoint to upload/download files? Then we need to come up with our own Authentication mechanism?

gedw99 commented 1 month ago

I mean having a HTTP file upload and download mechanism.

Yes I believe an authentication mechanism would be needed for this. I wonder if a nats based authentication would do, because then it can be managed by nats nsc, and so is globally synchronised in a NATS cluster.

I was also wondering about how we can notify a http client that the file has changed inside NATS , since NATS supports that. The gateway server could do a web hook , or a SSE event . In both cases , I think that the S3 API does not support that though.

gedw99 commented 1 month ago

Seems S3 supports file / bucket change events …

https://docs.aws.amazon.com/AmazonS3/latest/userguide/EventBridge.html

gedw99 commented 1 month ago

The client could use htmx.

so the gateway gets the event and then pushes it to a browser using htmx SSE.

the event would originate from NATS object store.

this file upload and download could also use the htmx.

https://github.com/chasefleming/elem-go Would do all this for use quite well. I already use this as it’s just golang with complete control over the look and feel using strongly typed golang to define the css etc

wpnpeiris commented 1 month ago

I mean having a HTTP file upload and download mechanism.

Yes I believe an authentication mechanism would be needed for this. I wonder if a nats based authentication would do, because then it can be managed by nats nsc, and so is globally synchronised in a NATS cluster.

I was also wondering about how we can notify a http client that the file has changed inside NATS , since NATS supports that. The gateway server could do a web hook , or a SSE event . In both cases , I think that the S3 API does not support that though.

Yeah, it would be nice to support a simple file upload/download REST API endpoints. Maybe it is something quick implement, so we don't need to adhere to protocol like S3.

gedw99 commented 1 month ago

Yeah that’s exactly what I was thinking .

that’s why I added the reference to event bridge . Because we have nats we ki d of have our own event bridge.