From 3c7c2b8559160edde6e14b3dc0a4770f2d5a6734 Mon Sep 17 00:00:00 2001 From: Wei Ouyang Date: Wed, 4 Sep 2024 13:30:39 -0700 Subject: [PATCH] Fix custom hypha-workspaces bug --- docs/operate-files.md | 58 +++++++++++++++++++++++++++-- helm-chart/hypha-server/values.yaml | 2 +- hypha/VERSION | 2 +- hypha/server.py | 3 ++ 4 files changed, 60 insertions(+), 5 deletions(-) diff --git a/docs/operate-files.md b/docs/operate-files.md index 9ad22fce..6d6d92ec 100644 --- a/docs/operate-files.md +++ b/docs/operate-files.md @@ -17,13 +17,12 @@ python3 -m hypha.server \ ``` ### Arguments: - - `--enable-s3`: Enables S3 object storage. - `--access-key-id`: Access key for the S3 server. - `--secret-access-key`: Secret key for the S3 server. - `--endpoint-url`: The internal URL for Hypha to access the S3 server. - `--endpoint-url-public`: Public URL for accessing the files (may be the same as `--endpoint-url`). -- `--s3-admin-type`: Specifies the S3 admin type (e.g., `minio`, `generic`). +- `--s3-admin-type`: Specifies the S3 admin type (e.g., `minio`, `generic`). If it's a minio server (not gateway mode), use `minio`, otherwise use `generic` would be enough for most cases. After starting Hypha with these arguments, you can verify that the S3 service is available by visiting the following URL: @@ -144,6 +143,57 @@ def operate_files_with_boto(info): # operate_files_with_boto(info) ``` +#### ** AWS SDK (JavaScript) ** + +```javascript +import { S3Client, PutObjectCommand, ListObjectsV2Command } from "@aws-sdk/client-s3"; + +const api = await connectToServer({ "server_url": "https://hypha.aicell.io" }); +const s3Controller = await api.getService("public/s3-storage"); +const info = await s3Controller.generateCredential(); + +const s3Client = new S3Client({ + region: info.region_name, + endpoint: info.endpoint_url, + credentials: { + accessKeyId: info.access_key_id, + secretAccessKey: info.secret_access_key, + }, +}); + +async function uploadFileToS3(file) { + try { + const uploadParams = { + Bucket: info.bucket, + Key: info.prefix + file.name, + Body: file, + }; + const data = await s3Client.send(new PutObjectCommand(uploadParams)); + console.log("File uploaded successfully:", data); + } catch (err) { + console.error("Error uploading file:", err); + } +} + +async function listFilesInS3() { + try { + const listParams = { + Bucket: info.bucket, + Prefix: info.prefix, + }; + const data = await s3Client.send(new ListObjectsV2Command(listParams)); + data.Contents.forEach((obj) => console.log(obj.Key)); + } catch (err) { + console.error("Error listing files:", err); + } +} + +// Example usage: +// const fileInput = document.getElementById("fileInput").files[0]; +// uploadFileToS3(fileInput); +// listFilesInS3(); +``` + ### 2. Using Presigned URLs @@ -185,7 +235,9 @@ async def upload_file(presigned_url: str, file_path: str): response = await client.put(presigned_url, content=file) print(response.status_code, response.reason_phrase) -# Example usage: +# + + Example usage: # asyncio.run(upload_file(upload_url, "myfile.txt")) ``` diff --git a/helm-chart/hypha-server/values.yaml b/helm-chart/hypha-server/values.yaml index e0b98cde..6beddde9 100644 --- a/helm-chart/hypha-server/values.yaml +++ b/helm-chart/hypha-server/values.yaml @@ -8,7 +8,7 @@ image: repository: ghcr.io/amun-ai/hypha pullPolicy: IfNotPresent # Overrides the image tag whose default is the chart appVersion. - tag: "0.20.33.post2" + tag: "0.20.33.post3" imagePullSecrets: [] nameOverride: "" diff --git a/hypha/VERSION b/hypha/VERSION index 003d9991..72bae34a 100644 --- a/hypha/VERSION +++ b/hypha/VERSION @@ -1,3 +1,3 @@ { - "version": "0.20.33.post2" + "version": "0.20.33.post3" } diff --git a/hypha/server.py b/hypha/server.py index 4f0f4193..dcf2f1b7 100644 --- a/hypha/server.py +++ b/hypha/server.py @@ -116,6 +116,7 @@ def start_builtin_services( endpoint_url=args.endpoint_url, access_key_id=args.access_key_id, secret_access_key=args.secret_access_key, + region_name=args.region_name, workspace_bucket=args.workspace_bucket, ) @@ -124,6 +125,8 @@ def start_builtin_services( endpoint_url=args.endpoint_url, access_key_id=args.access_key_id, secret_access_key=args.secret_access_key, + region_name=args.region_name, + workspace_bucket=args.workspace_bucket, base_path=args.base_path, )