Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FilePicker: How to read file content #444

Closed
mgordic opened this issue Dec 16, 2019 · 10 comments
Closed

FilePicker: How to read file content #444

mgordic opened this issue Dec 16, 2019 · 10 comments
Labels
Milestone

Comments

@mgordic
Copy link

mgordic commented Dec 16, 2019

Thank you for reporting an issue, suggesting an enhancement, or asking a question. We appreciate your feedback - to help the team understand your
needs please complete the below template to ensure we have the details to help. Thanks!

Please check out the documentation to see if your question is already addressed there. This will help us ensure our documentation is up to date.

Category

[ ] Enhancement

[ ] Bug

[x] Question

Version

Please specify what version of the library you are using: [ Latest ]

Expected / Desired Behavior / Question

How can I read file content on save, as array buffer or base64 encoded string?

downloadFileContent does not return anything of those.

Thank you

@ghost
Copy link

ghost commented Dec 16, 2019

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

@ghost ghost added the Needs: Triage 🔍 label Dec 16, 2019
@github-actions
Copy link

Thank you for submitting your first issue to this project.

@AJIXuMuK
Copy link
Collaborator

Hi @mgordic,

If you're not in IE or Edge, you can use Blob API to get ArrayBuffer or Stream (File implements Blob interface).

Documentation: https://developer.mozilla.org/en-US/docs/Web/API/File

@mgordic
Copy link
Author

mgordic commented Dec 19, 2019

Hi,

Thank you for your reply.

I need to support IE/Edge as well.

Do you maybe have some code example?

@AJIXuMuK
Copy link
Collaborator

@hugoabernier do you have any examples of that? I believe, this one was created by you (correct me if I wrong).

@hugoabernier
Copy link
Contributor

@AJIXuMuK as much as I'd like to take the credit for this control, it is based on a code sample I submitted to the WebParts samples repo. It appears that the code for this control is derived from one of my code sample in the https://github.com/SharePoint/sp-dev-fx-webparts repo. (I'd love to know who submitted the PR so that I can thank them directly though!)

If you're using IE or Edge, you should have access to msSaveOrOpenBlob. It will be undefined if not in Edge or IE.

@AJIXuMuK
Copy link
Collaborator

@hugoabernier it was Piotr Siatka @siata13

@siata13
Copy link
Contributor

siata13 commented Jan 13, 2020

Hey,
The implementation used File constructor which seems to be not supported in IE11.
I have created a bugfix and PR which should solve the issue.

Now, the downloadFileContent method should return a promise with a File object in IE also. After that, you can simply use FileReader, e.g.:

const fileResultContent = await filePickerResult.downloadFileContent();
const reader = new FileReader();
reader.readAsDataURL(fileResultContent);
reader.onload = async () => {
 // TODO: Implement your logic here.
};

@AJIXuMuK
Copy link
Collaborator

The PR has been merged and will be available in the next build. Or you can test it in current beta version.

@AJIXuMuK AJIXuMuK added this to the 1.17.0 milestone Jan 15, 2020
@AJIXuMuK AJIXuMuK added the status:fixed-next-drop Issue will be fixed in upcoming release. label Jan 15, 2020
@hugoabernier
Copy link
Contributor

Thanks @siata13 for doing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants