You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by "promer94 (via GitHub)" <gi...@apache.org> on 2023/03/26 11:23:11 UTC

[GitHub] [incubator-opendal] promer94 commented on a diff in pull request #1772: feat(bindings/nodejs): Support presign

promer94 commented on code in PR #1772:
URL: https://github.com/apache/incubator-opendal/pull/1772#discussion_r1148533288


##########
bindings/nodejs/index.d.ts:
##########
@@ -64,6 +64,24 @@ export class Operator {
    * An error will be returned if given path doesn't end with `/`.
    */
   listSync(path: string): BlockingLister
+  /**
+   * Get a presigned request for read.
+   *
+   * Unit of expires is seconds.
+   */
+  presignRead(path: string, expires: number): PresignedRequest
+  /**
+   * Get a presigned request for write.
+   *
+   * Unit of expires is seconds.
+   */
+  presignWrite(path: string, expires: number): PresignedRequest
+  /**
+   * Get a presigned request for stat.
+   *
+   * Unit of expires is seconds.
+   */
+  presignStat(path: string, expires: number): PresignedRequest

Review Comment:
   ## Benefit
   The benefit of presigned url is that data could be safely downloaded (uploaded) from(to) data storage without passing through the server.  
   It can save a lot of traffic and reduce the server load.
   
   ## Example usage
   
   * Redirect the client to download the data directly from the data storage
   ```js
   const server = http.createServer(async (req, res) => {
     if (req.url.startsWith('/download') && req.method === 'GET') {
       const urlParts = url.parse(req.url, true)
       const path = urlParts.query.path
       const expires = urlParts.query.expires
   
       const presignedRequest = op.presignRead(path, parseInt(expires))
   
       res.statusCode = 307
       res.setHeader('Location', presignedRequest.uri)
       res.end(end)
     } else {
       res.statusCode = 404
       res.end('Not Found')
     }
   })
   ```
   
   
   * Pass the `presignedRequest` to the client, client could build a stander web `request` from it.
   ```js
   const request = new Request(presignedRequest.uri, {
      headers: presignedRequest.headers,
      method: presignedRequest.method
   })
   fetch(request)
   ```
   
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org