betodealmeida commented on code in PR #34988:
URL: https://github.com/apache/superset/pull/34988#discussion_r2316584293


##########
superset-frontend/src/dashboard/hooks/useDownloadScreenshot.ts:
##########
@@ -98,12 +98,25 @@ export const useDownloadScreenshot = (
           headers: { Accept: 'application/pdf, image/png' },
           parseMethod: 'raw',
         })
-          .then((response: Response) => response.blob())
-          .then(blob => {
+          .then((response: Response) => {
+            const disposition = response.headers.get('Content-Disposition');
+            let filename = `screenshot.${format}`; // default filename
+
+            if (disposition && disposition.includes('filename=')) {
+              const filenameRegex = /filename="([^"]+)"/;
+              const matches = filenameRegex.exec(disposition);
+              if (matches && matches[1]) {
+                filename = matches[1];
+              }
+            }
+
+            return response.blob().then(blob => ({ blob, filename }));
+          })

Review Comment:
   It looks like we have `content-disposition` as a dependency already, so you 
can use it here:
   
   ```typescript
   // import contentDisposition from 'content-disposition';
   .then((response: Response) => {
     let filename = `screenshot.${format}`; // default filename
     const disposition = response.headers.get('Content-Disposition');
     
     if (disposition) {
       try {
         const parsed = contentDisposition.parse(disposition);
         filename = parsed.parameters.filename || filename;
       } catch (error) {
         // Fallback to default filename if parsing fails
         console.warn('Failed to parse Content-Disposition header:', error);
       }
     }
   
     return response.blob().then(blob => ({ blob, filename }));
   })
   ```



-- 
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: notifications-unsubscr...@superset.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org
For additional commands, e-mail: notifications-h...@superset.apache.org

Reply via email to