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

How to read image from local? #6

Closed
sc231997 opened this issue Aug 24, 2020 · 6 comments
Closed

How to read image from local? #6

sc231997 opened this issue Aug 24, 2020 · 6 comments

Comments

@sc231997
Copy link
Collaborator

sc231997 commented Aug 24, 2020

I am trying to use the file paths for the image (I am using the server extension). I am getting the following error.

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: invalid image, images dictionary should contain dataURL entries (or local file paths in node.js)
Microsoft.JSInterop.JSException: invalid image, images dictionary should contain dataURL entries (or local file paths in node.js)
  at System.Threading.Tasks.ValueTask`1[TResult].get_Result () <0x3715df8 + 0x00034> in <filename unknown>:0 
  at Microsoft.JSInterop.JSRuntimeExtensions.InvokeVoidAsync (Microsoft.JSInterop.IJSRuntime jsRuntime, System.String identifier, System.Object[] args) <0x33dc098 + 0x000e4> in <filename unknown>:0 
  at BlazorPdfMake.Demo.Pages.Images.OpenInNewTab () [0x00047] in E:\PdfMakeNet\BlazorPdfMake.Demo\Pages\Images.razor:134 
  at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion (System.Threading.Tasks.Task task) <0x34e84c8 + 0x000da> in <filename unknown>:0 
  at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask (System.Threading.Tasks.Task taskToHandle) <0x34e8d60 + 0x000b6> in <filename unknown>:0

I have tried using the absolute path as well but no luck there.

@arivera12
Copy link
Owner

arivera12 commented Aug 24, 2020

where are the images located? Can you show the snipped code you used for this?

@arivera12
Copy link
Owner

arivera12 commented Aug 24, 2020

Reading a file from Blazor WASM is not possible from disk read, you will need to expose the images under wwwroot folder and request them via HttpClient. For use the server extension PdfMakeNet should be running on Blazor Server side or MVC/api side so this extension is not for Blazor WASM. Blazor WASM works exactly as the browser does, no I/O operations directly to disk.

@sc231997
Copy link
Collaborator Author

I guess that answers my question.

Will it be a good idea to have some way of identifying if the string set was a file path and then convert to dataURL internally?

@arivera12
Copy link
Owner

arivera12 commented Aug 25, 2020

I don't think it's a good idea mixing this.

Images should be considered as base64 string always as pdfmake specs this.

How we would manage relative and absolute uri? We would need to set an httpclient for this.

What about if the resource/image we are trying to lookup is under authorization? We would still need to set an httpclient for this.

I think the idea is great and we should implement this options under an extension or helper methods.

If we are ok with this approach we should create a new issue with the proposed methods to implement.

What you think? How does this sounds?

@arivera12
Copy link
Owner

arivera12 commented Aug 25, 2020

For the demo purpose you can place an image under /wwwroot and request it with the httpclient.

@sc231997
Copy link
Collaborator Author

I don't think it's a good idea mixing this.

Images should be considered as base64 string always as pdfmake specs this.

How we would manage relative and absolute uri? We would need to set an httpclient for this.

What about if the resource/image we are trying to lookup is under authorization? We would still need to set an httpclient for this.

I think the idea is great and we should implement this options under an extension or helper methods.

If we are ok with this approach we should create a new issue with the proposed methods to implement.

What you think? How does this sounds?

This sounds good.

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

No branches or pull requests

2 participants