Telefonica / webview-bridge

Novum JavaScript Bridge
MIT License
26 stars 7 forks source link

SHARE_BASE64 New method to share files in base64 #138

Open dagonco opened 3 weeks ago

dagonco commented 3 weeks ago

Due to the new requirement to be able to generate invoices and that they can be shared or downloaded by the user. It is necessary to create a new bridge method since these invoices cannot be hosted anywhere. These files could be of any type (pdfs or zips).

Documentation:

ShareBase64

shareBase64: ({ content: string, fileName: string }) => Promise<void>
Request → { type: "SHARE_BASE64", id: string, payload: { content: "base64 string", fileName: "fileName.ext" } } 
Response → { type: "SHARE_BASE64", id: string }

Success response

Empty response.

Error response codes

400 → Bad request: If payload is null or there's any missing mandatory parameter. 500 → Internal Error: If an error occurred while processing the file

Discarded ideas

amegias commented 3 weeks ago

I would improve the example:

- Request → { type: "SHARE_BASE64", id: string, payload: { content: "base64 string", fileName?: "pdfname" } } 
+ Request → { type: "SHARE_BASE64", id: string, payload: { content: "base64 string", fileName: "pdfname.pdf" } } 
Response → { type: "SHARE_BASE64", id: string }

I guess the extension will come in the fileName right? In addition, can fileName be null? I would force it as mandatory, wdyt?

dagonco commented 3 weeks ago

I left it optional because for the SHARE method this filename field does not exist, and we are the ones who put "Document" as the file prefix, same with the extension.

But I dont have a strong opinion to let it mandatory and let web to put the extension, I just wanted to reuse all SHARE logic possible.

alejandroruizponce commented 2 weeks ago

I would improve the example:

- Request → { type: "SHARE_BASE64", id: string, payload: { content: "base64 string", fileName?: "pdfname" } } 
+ Request → { type: "SHARE_BASE64", id: string, payload: { content: "base64 string", fileName: "pdfname.pdf" } } 
Response → { type: "SHARE_BASE64", id: string }

I guess the extension will come in the fileName right? In addition, can fileName be null? I would force it as mandatory, wdyt?

I left it optional because for the SHARE method this filename field does not exist, and we are the ones who put "Document" as the file prefix, same with the extension.

But I dont have a strong opinion to let it mandatory and let web to put the extension, I just wanted to reuse all SHARE logic possible.

I don't see the point in making this parameter optional. It implies that at the time of showing the modal Share if the filename is null we have to define a name for the file that we are going to share. I believe that this responsibility should come to us made from webapp and always receive a name with which we want to share the file.

dpastor commented 2 weeks ago

I would improve the example:

- Request → { type: "SHARE_BASE64", id: string, payload: { content: "base64 string", fileName?: "pdfname" } } 
+ Request → { type: "SHARE_BASE64", id: string, payload: { content: "base64 string", fileName: "pdfname.pdf" } } 
Response → { type: "SHARE_BASE64", id: string }

I guess the extension will come in the fileName right? In addition, can fileName be null? I would force it as mandatory, wdyt?

I left it optional because for the SHARE method this filename field does not exist, and we are the ones who put "Document" as the file prefix, same with the extension. But I dont have a strong opinion to let it mandatory and let web to put the extension, I just wanted to reuse all SHARE logic possible.

I don't see the point in making this parameter optional. It implies that at the time of showing the modal Share if the filename is null we have to define a name for the file that we are going to share. I believe that this responsibility should come to us made from webapp and always receive a name with which we want to share the file.

We agreed on making filename mandatory, modifying spec.

nimeacuerdo commented 1 week ago

what is left to proceed with this?

pladaria commented 1 week ago

Has this been considered? https://developer.mozilla.org/en-US/docs/Web/API/Web_Share_API

Web Share API is not supported in android webviews. So this proposal LGTM