mostafa-mansour1 / previewAnyFile

Cordova Plugin to preview any file in native mode by providing the local or external URL
MIT License
33 stars 31 forks source link

Failure to use this plugin in my Ionic 5 app to view excel from assets #20

Closed skyleguy closed 3 years ago

skyleguy commented 3 years ago

in my /assets i have test.xlsx and I am attempting to use this plugin like so:

After running:

npm install @ionic-native/preview-any-file --save ionic cordova plugin add cordova-plugin-preview-any-file --save

/* app.module.ts */
import { PreviewAnyFile } from '@ionic-native/preview-any-file/ngx';
...
providers: [PreviewAnyFile]
...

/* test.component.ts */
constructor(private previewAnyFile: PreviewAnyFile) {}

public viewFile(): void {
      this.previewAnyFile
      .preview('/assets/test.xlsx')
      .then((res): any => {
        console.log(res);
      })
      .catch((err: any): any => {
        console.log(err);
      });
}

but it claims that the url is not supported and i even get a warning to use previewAsset as preview is deprecated. However when i try to use preivewAsset it says the method does not exist. Any help with this? I found this plugin from the ionic documentation at: https://ionicframework.com/docs/native/preview-any-file

mostafa-mansour1 commented 3 years ago

Unfortunately, my pull request for update ionic native plugin didn't process till now,

So if you need to use the plugin, you have to use it without the ionic native interface,

here is how to use it directly

  (<any>window).PreviewAnyFile.previewAsset(
        win => console.log("open status",win),
        error => console.error("open failed", error),
        '/assets/test.xlsx'
    );
mostafa-mansour1 commented 3 years ago

also if you really need the ionic interface wrapper, you have to update the folder in node_moduls with this folder in this comment

https://github.com/mostafa-mansour1/previewAnyFile/issues/14#issuecomment-771783669

skyleguy commented 3 years ago

Thank you! I did see your PR to the ionic native repo but I'm pretty unfamiliar with the timing here, do you have an estimate on when you think that might make it into an available version?

mostafa-mansour1 commented 3 years ago

Actually, I don’t have any idea, first release it was published same day, btw you have the way to use thee plugin

On 12 Mar 2021, at 10:53 PM, Kyle @.**@.>> wrote:

Thank you! I did see your PR to the ionic native repo but I'm pretty unfamiliar with the timing here, do you have an estimate on when you think that might make it into an available version?

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/mostafa-mansour1/previewAnyFile/issues/20#issuecomment-797682559, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABSFOB7VVNZRFAQOPO5NDA3TDJIK3ANCNFSM4ZCT6DKQ.

skyleguy commented 3 years ago

thank you for the speedy replies. After using the code snippet you supplied and also replacing my preview-any-file folder you supplied in the other comment i am still not seeing the preview show up. I know its working because i accidentally spelled my file name wrong and your plugin printed a warning about the file not being at the specified location/couldnt find the file. but now that its typed correctly im getting no error or success showing up. any thoughts?

mostafa-mansour1 commented 3 years ago

First of all, try to remove the plugin, then build the app again, then add the plugin again, and build again

that to sure all files went to the correct place, after that try to run from Xcode or android studio ( depend on your app)

then click on your link and check the debugging, if there is an error it may appear

If you failed, please WhatsApp me to go in details https://wa.me/971524988466

skyleguy commented 3 years ago

hey, took a little while to generate my application but i've made a bare bones app to try and recreate my issue seen in the main app i use. https://github.com/skyleguy/cordova-preview-any-file-test all it does is wait 5 seconds from app start and then try to view an xlsx file in the assets folder called 'Budgeting.xlsx'. nothing seems to happen even though the call to previewAsset is firing. You 'should' be able to just run npm i and then npm run build:ios to open the app in xcode

mostafa-mansour1 commented 3 years ago

I will check it tomorrow morning, and i will get back to you

Regards,


Mostafa Mansour Software Engineer 00971 524988466 0020 1113019196

On 13 Mar 2021, at 12:57 AM, Kyle @.***> wrote:



hey, took a little while to generate my application but i've made a bare bones app to try and recreate my issue seen in the main app i use. https://github.com/skyleguy/cordova-preview-any-file-test all it does is wait 5 seconds from app start and then try to view an xlsx file in the assets folder called 'Budgeting.xlsx'. nothing seems to happen even though the call to previewAsset is firing

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/mostafa-mansour1/previewAnyFile/issues/20#issuecomment-797750525, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABSFOB45AXY7ZE4J2XJCGD3TDJW3BANCNFSM4ZCT6DKQ.

skyleguy commented 3 years ago

honestly i wouldn't worry about it too much for my sake, i just got a version working with excel files using the previewBase64 method (which is what we'd probably actually be going with) and its pretty cool! the export option already shows the excel app as an option to open/save which lets me download an excel file from my app, open in the excel app, and save to my companies one drive 👍 Is there a way to modify the preview? on my iPhone 12 Pro the area above the grey header bar looks a bit off as the grey just stops and white fills the notch-area. would be nice if the grey continued all the way into the safe area. its hard to tell from this picture but the export options in the bottom left are also a little hard to click due to the curvature of the phone. Overall very cool thank you for this!

It is rather annoying having to make a network call to retrieve my excel file, convert to base 64, and then previewBase64, does the previewPath method take headers as an option so i can hit an endpoint that takes authorization? That would be nice to use if it stops me from having to base64 my ArrayBuffer response.

Here is the image of my iphone that i referenced above, you can see the area where the battery icon is is completely white and looks a little funky. Picture does not show at all the export icon issue i mentioned though: ___

Screen Shot 2021-03-12 at 7 18 42 PM

mostafa-mansour1 commented 3 years ago

Hi I am happy to know that it’s working with you Actually the preview asset method is trying to get the base64 to path it to the native And from native we create a temp file with this base64 From options you can change the name of the files About the safe area, I tested it on iphone x, iphone xs, iphone 11 And it didn’t go to the safe area I recommended you to try on device rather than the emulator

Regards,


Mostafa Mansour Software Engineer 00971 524988466 0020 1113019196

On 13 Mar 2021, at 4:23 AM, Kyle @.***> wrote:



honestly i wouldn't worry about it too much for my sake, i just got a version working with excel files using the previewBase64 method (which is what we'd probably actually be going with) and its pretty cool! the export option already shows the excel app as an option to open/save which lets me download an excel file from my app, open in the excel app, and save to my companies one drive 👍 Is there a way to modify the preview? on my iPhone 12 Pro the area above the grey header bar looks a bit off as the grey just stops and white fills the notch-area. would be nice if the grey continued all the way into the safe area. its hard to tell from this picture but the export options in the bottom left are also a little hard to click due to the curvature of the phone. Overall very cool thank you for this!

It is rather annoying having to make a network call to retrieve my excel file, convert to base 64, and then previewBase64, does the previewPath method take headers as an option so i can hit an endpoint that takes authorization? That would be nice to use if it stops me from having to base64 my ArrayBuffer response.

Here is the image of my iphone that i referenced above:

[Screen Shot 2021-03-12 at 7 18 42 PM]https://user-images.githubusercontent.com/14967057/111011733-4f960000-8368-11eb-9482-68bb44e4b1bb.png

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/mostafa-mansour1/previewAnyFile/issues/20#issuecomment-797828981, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABSFOB4PJEGZ4D6MBWZ2VHDTDKO5FANCNFSM4ZCT6DKQ.

skyleguy commented 3 years ago

I was actually deploying to my iPhone 12 Pro, not using a simulator when I took that picture. I did have to use the options argument to supply the mime type but when I tried to add name it seemed to stop working. This would be the correct object to supply mimetype and name right?

{ name: “myName.xlsx”, mimeType: “application/...”}

On Sat, Mar 13, 2021 at 2:42 AM Mostafa Mansour @.***> wrote:

Hi I am happy to know that it’s working with you Actually the preview asset method is trying to get the base64 to path it to the native And from native we create a temp file with this base64 From options you can change the name of the files About the safe area, I tested it on iphone x, iphone xs, iphone 11 And it didn’t go to the safe area I recommended you to try on device rather than the emulator

Regards,


Mostafa Mansour Software Engineer 00971 524988466 0020 1113019196

On 13 Mar 2021, at 4:23 AM, Kyle @.***> wrote:



honestly i wouldn't worry about it too much for my sake, i just got a version working with excel files using the previewBase64 method (which is what we'd probably actually be going with) and its pretty cool! the export option already shows the excel app as an option to open/save which lets me download an excel file from my app, open in the excel app, and save to my companies one drive 👍 Is there a way to modify the preview? on my iPhone 12 Pro the area above the grey header bar looks a bit off as the grey just stops and white fills the notch-area. would be nice if the grey continued all the way into the safe area. its hard to tell from this picture but the export options in the bottom left are also a little hard to click due to the curvature of the phone. Overall very cool thank you for this!

It is rather annoying having to make a network call to retrieve my excel file, convert to base 64, and then previewBase64, does the previewPath method take headers as an option so i can hit an endpoint that takes authorization? That would be nice to use if it stops me from having to base64 my ArrayBuffer response.

Here is the image of my iphone that i referenced above:

[Screen Shot 2021-03-12 at 7 18 42 PM]< https://user-images.githubusercontent.com/14967057/111011733-4f960000-8368-11eb-9482-68bb44e4b1bb.png>

— You are receiving this because you commented. Reply to this email directly, view it on GitHub< https://github.com/mostafa-mansour1/previewAnyFile/issues/20#issuecomment-797828981>, or unsubscribe< https://github.com/notifications/unsubscribe-auth/ABSFOB4PJEGZ4D6MBWZ2VHDTDKO5FANCNFSM4ZCT6DKQ>.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mostafa-mansour1/previewAnyFile/issues/20#issuecomment-797884520, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADSGCEJEN6EFE3LPXI3D2TTTDMJPBANCNFSM4ZCT6DKQ .