Code Monkey home page Code Monkey logo

previewanyfile's Introduction

Preview Any File

Whatever the file is PDF document, Word document, Excel, office document, archive file, image, text, html or anything else, you can perform a preview by this awesome cordova Plugin to preview any file in native mode by providing the local or external URL.

From version 0.2.0, you can preview the file from any where, you can use base64 or local file from assets or local files from the device or even from internet.

From version 0.2.0, you can overwrite the file name or its mime type, if the file has no extension at the end of the path

you can find the project at github

https://github.com/mostafa-mansour1/previewAnyFile

How it work

For IOS

Using the built-in class QLPreviewController, A QLPreviewController can display previews for the following items:

  • iWork documents
  • Microsoft Office documents (Office ‘97 and newer)
  • Rich Text Format (RTF) documents
  • PDF files
  • Images
  • Text files whose uniform type identifier (UTI) conforms to the public.text type (see Uniform Type Identifiers Reference)
  • Comma-separated value (csv) files
  • 3D models in USDZ format (with both standalone and AR views for viewing the model)

for any other file it will present the preview with message "cannot preview file" and there is a button to save the file in the device

For Android

Android not like ios, there is no way to render the file directly, the user must install a suitable application for every type.

So I used Intent.ACTION_VIEW to preview the file,

if there is a suitable application already installed in the user device it will preview the file directly,

if not, it will ask the user to select an application

the file path in android must be absolute path to the file starting with file:// or content://

Install

$ cordova plugin add cordova-plugin-preview-any-file --save

for ionic projects

$ ionic cordova plugin add cordova-plugin-preview-any-file --save

Usage

Use this code to preview the file,

if the correct extension not exist at the last of the file path like file://filepath/filename.ext you must define the file name or its mimeType in the 2nd params {name:'file.png',mimeType : 'image/png'}

- View or Open file from the device

    window.PreviewAnyFile.previewPath(
        win =>
            {
                if (win == "SUCCESS") {
                    console.log('success')
                } else if (win == "CLOSING") {
                    console.log('closing')
                } else if (win == "NO_APP") {
                    console.log('no suitable app to open the file (mainly will appear on android')
                } else {
                    console.log('error')
                }
            },
        error => console.error("open failed", error),
        "file://filepath/filename.ext"
    );

- View or Open file from an external link

you can use external link, the preview will not opened until the file downloaded successfully, so present loader before call the function then dismiss it in call back, you can define the name of the file or its mimeType in the options

    // add your code here  to show loader

    window.PreviewAnyFile.previewPath(
        win => console.log("open status",win),
        error => console.error("open failed", error),
        "http://www.domain.com/samplefile",{name : file.pdf}
    );

- View or Open base64 file

    window.PreviewAnyFile.previewBase64(
        win => console.log("open status",win),
        error => console.error("open failed", error),
        'data:image/gif;base64,R0lGODlhP.....'
    );

    // you must define the mimeType or file name if the base64 string has no media type
    window.PreviewAnyFile.previewBase64(
        win => console.log("open status",win),
        error => console.error("open failed", error),
        'JVBERi0xLjMKJcTl8uXr.....',{mimeType:'application/pdf'}
    );

- View or Open file from the asset folder

    window.PreviewAnyFile.previewAsset(
        win => console.log("open status",win),
        error => console.error("open failed", error),
        '/assets/localFile.pdf'
    );

    // you must define the mimeType or file name if the base64 string has no media type
    window.PreviewAnyFile.previewBase64(
        win => console.log("open status",win),
        error => console.error("open failed", error),
        '/assets/fileWithoutExt',{mimeType:'application/pdf',name:'file.pdf'}
    );

Supported platforms

  • Android
  • iOS

Change Log

-- version 0.2.9

  • (Android) fix Android AppCompat version to 1.3.1 #37 (#37)

-- version 0.2.8

  • (IOS) fix issue some base64 not preview if it has the full mimetype

-- version 0.2.7

  • (IOS) fix issue reported by @Siedlerchr #26 (#26)

-- version 0.2.6

  • (IOS) fix issue reported by @Siedlerchr #23 (#23)

-- version 0.2.3

  • (IOS) add CoreServices.framework to prevent build issues

-- version 0.2.2

  • (Android) prevent application crashing on null

-- version 0.2.1

  • fix compatibility with Ionic Capacitor

-- version 0.2.0

  • (deprecated method) preview method will marked as deprecated, you have to use previewPath instead.
  • add new methods to preview/open any file from any where (base64, asset folder, public url, locale file with any schema )
  • (Android) add CLOSING callback when user finish the preview
  • (Android) fix issue when open file:// or content:// (now you can view the file directly without resolve any path)

-- version 0.1.7

  • add callback when closing in IOS (thank @drewwynne0)

-- version 0.1.6

  • fix minor issues

-- version 0.1.5

  • (Android) Temporary fix for the issue that file not opened in SDK > 28

-- version 0.1.4

  • (Android) fix issue getting the file extension

-- version 0.1.3

  • (IOS) fix issue when provide a path of the file not the url , now it accept path that start with "/" or url start with "file://"
  • (IOS) fix issue if open external link more then one time
  • (IOS, Android) fix call back

-- version 0.1.2

  • update readme to add documentation

-- version 0.1.1

  • initial the plugin

known Issues

  • cannot open https url in android

TO DO

  • add ionic wrapper (Done)
  • support to view base64 string directly (Working on it)

previewanyfile's People

Contributors

drewwynne0 avatar mostafa-mansour1 avatar siedlerchr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

previewanyfile's Issues

Unable to view file stored at Azure Storage Explorer

Hi I having trouble to preview file such as image and pdf using url from azure storage explorer that also contain with the SaS token, before that i did try using inAppBrowser which i able to view those file without problem. I did aso tested out using sample image from google which able to view the image using this previewAnyFile. Below attached image are the output i get after i launch the function Thanks.
image
image

   // jpgUrl = 'https://........blob.core.windows.net/...../Andy.jpg?sp=.......(SaStoken)';
  openImage(){
    this.previewAnyFile.preview(this.jpgUrl).then(()=>{

    },(err)=>{
      alert(JSON.stringify(err));
    })

  }

Android build fails - AAPT: error: resource android:attr/lStar not found

Because of the android core:core:1.7.0 update I'll get an error while building an app for android. No changes on the app made but suddenly I’ll became the error Android resource linking failed. AAPT: error: resource android:attr/lStar not found. I'll started to remove plugin for plugin and when I'll remove previewAnyFile I'll be able to build again and the error disappears. I'll also tried to update from previewAnyFile version 0.2.3 to 0.2.8 and 0.2.9 but still get the same error. Hope there is a fix for this.

Full Error

> Task :app:processDebugResources FAILED
AGPBI: {"kind":"error","text":"Android resource linking failed","sources":[{"file":"/Users/username/.gradle/caches/transforms-2/files-2.1/a569d3e74eb4c0df31a2aa81dc055565/core-1.7.0-beta02/res/values/values.xml","position":{"startLine":104,"startColumn":4,"startOffset":6400,"endLine":113,"endColumn":24,"endOffset":6854}}],"original":"/Users/username/.gradle/caches/transforms-2/files-2.1/a569d3e74eb4c0df31a2aa81dc055565/core-1.7.0-beta02/res/values/values.xml:105:5-114:25: AAPT: error: resource android:attr/lStar not found.\n    ","tool":"AAPT"}

Execution failed for task ':app:processDebugResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > Android resource linking failed
     /Users/username/.gradle/caches/transforms-2/files-2.1/a569d3e74eb4c0df31a2aa81dc055565/core-1.7.0-beta02/res/values/values.xml:105:5-114:25: AAPT: error: resource android:attr/lStar not found.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

I'll know that there is a way to force the core:core version in de app/build.gradle like down here. But unfortunately that's not suitable for my project because this doen't work / applied when building builds with ionic appflow.

configurations.all {
    resolutionStrategy {
        force "androidx.core:core:1.6.0"
    }
}

Ionic info

Ionic:

   ionic (Ionic CLI)             : 4.12.0 (/usr/local/lib/node_modules/ionic)
   Ionic Framework               : @ionic/angular 5.2.3
   @angular-devkit/build-angular : 0.1100.7
   @angular-devkit/schematics    : 9.1.11
   @angular/cli                  : 10.0.8
   @ionic/angular-toolkit        : 2.3.0

Capacitor:

   capacitor (Capacitor CLI) : 2.5.0
   @capacitor/core           : 2.5.0

System:

   NodeJS : v14.17.0 (/usr/local/bin/node)
   npm    : 6.14.13
   OS     : macOS

Obejct is not function

why when i am add this plugin to my ionic 3 projects, and even i am finished build/compile my project. Then when i want use it. Its show error like this.
ERROR TypeError: Object(...) is not a function at e.preview (vendor.js:1) at l.download (main.js:1) at Object.handleEvent (0.js:1) at Object.handleEvent (vendor.js:1) at Object.handleEvent (vendor.js:1) at Ut (vendor.js:1) at vendor.js:1 at HTMLElement.<anonymous> (vendor.js:1) at t.invokeTask (polyfills.js:3) at Object.onInvokeTask (vendor.js:1)

Thats my code,

me.previewFile.preview("file:///storage/emulated/0/MyRadiant/Form_Pengkinian_Data_(Individual)_(2).pdf") .then((res: any) => console.log(res)) .catch((error: any) => console.error("eror hehe",error));

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

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

Saving a document on Android device

I am using latest version of your plugin.
I have a specific case when an error occurs. A link is sent to me from the server that does not have an extension. In this case i am using 'previewPath' method. also i have next parameters: mimeType : 'application/pdf', name: 'test.pdf' . When i open this document on Android device the name of it (on the top header ) is without extension and when i click 'download' it saves it as a file without extension. iOS works correctly. And saving works correctly if my url contains extension. Can you check it pls in your side?

why download pdf not view?

hello this is my code
const viewUrl = 'http://www.africau.edu/images/default/sample.pdf'; this.previewAnyFile.preview(viewUrl).then(resp => { console.log(resp); }, err => { console.log(err); });
on android device it download file not view why?

New Release for bugfix PR

Hi,

I just noticed that while you merged my PR #40, there is no new release for my fix. I would appreciate it if you could publish a new version which contains that fix, because today I ran into this again after reinstalling.

Android AppCompat Beta 1.4.0-beta01 Release Breaks Builds

The following line <framework src="androidx.appcompat:appcompat:+" /> in the plugin.xml file is now breaking Android Builds for SDKCompile versions less than 31 which is what I imagine all Capacitor projects are running with.

With the release of the new 1.4.0-beta01 : https://developer.android.com/jetpack/androidx/releases/appcompat which happened yesterday all builds using this plugin with SDK less than 31 will now break.

I would recommended instead of using + we just lock the version to 1.3.1 as this is the most recent stable version per the site. Let me know your thoughts and I can open a PR if need be. I've fixed it in our build pipeline for now by hacking around it but wouldn't mind solving it at the core for others using the plugin / having the same issue.

Thanks for the great plugin!

Update npm listing

Could you update the npm listing to include the links to this repo?

The plugin will then be usable by VoltBuilder.

previewAnyFile.previewBase64 error

Hi,
I use previewAnyFile.previewBase64 in ionicvue to open base64 pdf like:

      previewAnyFile.previewBase64('data:application/pdf;base64,.......')
      .catch((error: any) => showError(error));

and got this error:
Error: the old format of this exec call has been removed (deprecated since 2.1). Change to: cordova.exec(null, null, 'Service', 'action', [arg1, arg2]);

I know you have a zip file provided for AngularJs as a fix, do you have a fix for Ionicvue, too ? e.g. correct the preview.js in
\android\app\src\main\assets\public\plugins\cordova-plugin-preview-any-file\www

Thanks

Ionic 3 project - TypeError: Object(...) is not a function

I am getting this error TypeError: Object(...) is not a function at this.previewAnyFile.preview() method. Is it something related to not support of this plugin on Ionic 3. I have installed this version in an Ionic 3 project. Is there any way to use this plugin with "ionic-angular": "3.9.2"?

IOS 15: Unable to simultaneously satisfy constraints warning

I recently just noticed that whenever I preview a file using IOS 15 I get this warning on each file type.

2022-06-10 09:34:49.734778-0400 App[7032:387972] [LayoutConstraints] Unable to simultaneously satisfy constraints.
	Probably at least one of the constraints in the following list is one you don't want. 
	Try this: 
		(1) look at each constraint and try to figure out which you don't expect; 
		(2) find the code that added the unwanted constraint or constraints and fix it. 
	(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x281dce530 h=-&- v=--& UINavigationBar:0x1035f8400.minY == 0   (active, names: '|':UILayoutContainerView:0x103a4ce40 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x281dcc0a0 h=-&- v=--& UINavigationBar:0x1035f8400.height == 44   (active)>",
    "<NSLayoutConstraint:0x281dcc050 V:[UINavigationBar:0x1035f8400]-(0)-[UIFocusContainerGuide:0x2801b80f0'UINavigationControllerContentFocusContainerGuide']   (active)>",
    "<NSLayoutConstraint:0x281dce120 UIFocusContainerGuide:0x2801b80f0'UINavigationControllerContentFocusContainerGuide'.bottom == UILayoutContainerView:0x103a4ce40.bottom   (active)>",
    "<NSLayoutConstraint:0x281dcd270 V:|-(0)-[UILayoutContainerView:0x103a4ce40]   (active, names: QLPreviewControllerView:0x1035f4640, '|':QLPreviewControllerView:0x1035f4640 )>",
    "<NSLayoutConstraint:0x281dcd2c0 V:[UILayoutContainerView:0x103a4ce40]-(0)-|   (active, names: QLPreviewControllerView:0x1035f4640, '|':QLPreviewControllerView:0x1035f4640 )>",
    "<NSLayoutConstraint:0x281dccd70 'UIView-Encapsulated-Layout-Height' QLPreviewControllerView.height == 0   (active, names: QLPreviewControllerView:0x1035f4640 )>"
)

I am not sure if IOS changed something but did some research and based on - https://stackoverflow.com/questions/62542478/constraints-issue it seems you would need to apply a constraint. Was wondering if others are experiencing this issue as well

I also found this: fcf383a. Not sure if that helps with putting us on the right track to resolve it

Unable to run the code on iOS

I am unable to run the code in Angular/Cordova for iOS version 14.6 :
Below is the stack trace

Error: The old format of this exec call has been removed (deprecated since 2.1). Change to: cordova.exec(null, null, 'Service', 'action', [ arg1, arg2 ]);
iOSExec — ios-wkwebview-exec.js:103
execProxy — ios-wkwebview-exec.js:151
(anonymous function) — preview.js:16
(anonymous function) — common.js:48
(anonymous function) — common.js:8
ZoneAwarePromise — zone-evergreen.js:960
tryNativePromise — common.js:7
wrapPromise — common.js:31
previewBase64 — preview-file.service.ts:21
openAsImage — map-info-collection.component.ts:273
openMapInSelectedFormat — map-info-collection.component.ts:215
(anonymous function) — map-info-collection.component.ts:187
generatorResume
(anonymous function) — tslib.es6.js:76
ZoneAwarePromise — zone-evergreen.js:960
__awaiter — tslib.es6.js:72
listener — events.js:50
(anonymous function) — Target.js:114:84
(anonymous function) — Composite.js:76
(anonymous function) — PluggableMap.js:902
(anonymous function) — PluggableMap.js:1177
onInvokeTask — core.js:28564
runTask — zone-evergreen.js:167
invokeTask — zone-evergreen.js:480
timer — zone-evergreen.js:2552

Capacitor cordova-plugin-androidx error

Hello, the latest update v0.2.0 apparently uses cordova-plugin-androidx on Android and I can no longer build my project on Android. iOS works very well.

This is my error if I try to build the code in AndroidStudio.
I don't think this is a specific problem with previewAnyFile, but maybe you have a solution for Capacitor functionality.

> Task :app:processDebugManifest FAILED /Users/****/Apps/my-app/android/app/src/main/AndroidManifest.xml:36:13-64 Error: Attribute provider#androidx.core.content.FileProvider@authorities value=(app.my-app.fileprovider) from AndroidManifest.xml:36:13-64 is also present at [:capacitor-cordova-android-plugins] AndroidManifest.xml:17:13-60 value=(app.my-app.provider). Suggestion: add 'tools:replace="android:authorities"' to <provider> element at AndroidManifest.xml:34:9-42:20 to override. /Users/****/Apps/my-app/android/app/src/main/AndroidManifest.xml:41:17-51 Error: Attribute meta-data#android.support.FILE_PROVIDER_PATHS@resource value=(@xml/file_paths) from AndroidManifest.xml:41:17-51 is also present at [:capacitor-cordova-android-plugins] AndroidManifest.xml:22:17-54 value=(@xml/preview_paths). Suggestion: add 'tools:replace="android:resource"' to <meta-data> element at AndroidManifest.xml:39:13-41:64 to override.

Bug: ERROR Class not found On Android (Capacitor 3)

When using on Capacitor 3 for Android I am getting the following error in the logcat console. Line 34005 - Msg: ERROR Class not found

I am using React and Capacitor 3 to implement the plugin which is working as expected on IOS but throws the error above on Android. Below is the custom hook that wraps this plugin.

const useNativeFilePreview = ({ fileId, isVault, workspaceId }) => {
  const [isLoading, setIsLoading] = useState(false);
  const isNative = Capacitor.isNativePlatform();
  const queryClient = useQueryClient();
  const toast = useToast();

  const fileContentArgs = isVault
    ? { queryClient, fileId }
    : { queryClient, fileId, workspaceId };

  const onSuccess = () => {
    setIsLoading(false);
  };

  const onError = (e) => {
    console.log('ERROR', e);
    toast({
      title: 'Error Opening File Note',
      description: 'Any error occured during preview.',
      status: 'error',
      duration: TOAST_DURATION,
      isClosable: true,
    });
    setIsLoading(false);
  };

  const previewNativeFile = async (fileName) => {
    if (isNative && !CACHE[fileName]) {
      setIsLoading(true);
      const fileContent = await downloadFileContents(fileContentArgs);
      const response = await fetch(fileContent);
      const blob = await response.blob();
      const result = await write_blob({
        path: fileName,
        blob: blob,
        directory: Directory.Cache,
      });
      console.log('FILE DL -- WRITE', result);
      CACHE[fileName] = result;
      await window.PreviewAnyFile.previewPath(onSuccess, onError, result);
    } else if (isNative && CACHE[fileName]) {
      await window.PreviewAnyFile.previewPath(
        onSuccess,
        onError,
        CACHE[fileName]
      );
    }
  };

  return { previewNativeFile, isLoading };
};

export default useNativeFilePreview;

I have been unable to trace down where exactly the error is occurring or what is causing it. However I can confirm it happens on the await window.PreviewAnyFile.previewPath(onSuccess, onError, result); line

UI API called on a background thread: -[UIViewController init]

Hi,

I found another smalll issue:
in Thread Checker: UI API called on a background thread: -[UIViewController init]
The fix is simple. The init of the PrevieControl has to be moved to the Main Thread.

Backtrace:
4   myapp                          0x0000000104890710 $sSo19QLPreviewControllerCABycfcTO + 24
5   myapp                          0x0000000104888800 $sSo19QLPreviewControllerCABycfC + 32
6   myapp                          0x0000000104889e34 $s10myapp14PreviewAnyFileC11previewPath8_commandySo20CDVInvokedUrlCommandC_tFySb_10Foundation3URLVSgSo7NSErrorCSgtcfU_ + 672
7   myapp                          0x000000010488f970 $s10myapp14PreviewAnyFileC12downloadfile8withName04fileG010completionySS_SSySb_10Foundation3URLVSgSo7NSErrorCSgtctFyAK_So13NSURLResponseCSgs5Error_pSgtcfU_ + 1292
8   myapp                          0x000000010488fdf4 $s10Foundation3URLVSgSo13NSURLResponseCSgs5Error_pSgIegngg_So5NSURLCSgAGSo7NSErrorCSgIeyByyy_TR + 412
9   CFNetwork                           0x0000000186496400 CFNetServiceBrowserSearchForServices + 75244
10  CFNetwork                           0x00000001864abc4c _CFHTTPMessageSetResponseProxyURL + 18640
11  libdispatch.dylib                   0x0000000105fc40b4 _dispatch_call_block_and_release + 32
12  libdispatch.dylib                   0x0000000105fc5de0 _dispatch_client_callout + 20
13  libdispatch.dylib                   0x0000000105fcdef0 _dispatch_lane_serial_drain + 788
14  libdispatch.dylib                   0x0000000105fced48 _dispatch_lane_invoke + 496
15  libdispatch.dylib                   0x0000000105fdba50 _dispatch_workloop_worker_thread + 1600
16  libsystem_pthread.dylib             0x00000001d0dba7a4 _pthread_wqthread + 276
17  libsystem_pthread.dylib             0x00000001d0dc174c start_wqthread + 8
2021-06-10 11:02:00.295861+0200 myapp[1102:422107] [reports] Main Thread Checker: UI API called on a background thread: -[UIViewController init]
PID: 1102, TID: 422107, Thread name: (none), Queue name: com.apple.NSURLSession-delegate, QoS: 0
Backtrace:
4   myapp                          0x0000000104890710 $sSo19QLPreviewControllerCABycfcTO + 24
5   myapp                          0x0000000104888800 $sSo19QLPreviewControllerCABycfC + 32
6   myapp                          0x0000000104889e34 $s10myapp14PreviewAnyFileC11previewPath8_commandySo20CDVInvokedUrlCommandC_tFySb_10Foundation3URLVSgSo7NSErrorCSgtcfU_ + 672
7   myapp                          0x000000010488f970 $s10myapp14PreviewAnyFileC12downloadfile8withName04fileG010completionySS_SSySb_10Foundation3URLVSgSo7NSErrorCSgtctFyAK_So13NSURLResponseCSgs5Error_pSgtcfU_ + 1292
8   myapp                          0x000000010488fdf4 $s10Foundation3URLVSgSo13NSURLResponseCSgs5Error_pSgIegngg_So5NSURLCSgAGSo7NSErrorCSgIeyByyy_TR + 412
9   CFNetwork                           0x0000000186496400 CFNetServiceBrowserSearchForServices + 75244
10  CFNetwork                           0x00000001864abc4c _CFHTTPMessageSetResponseProxyURL + 18640
11  libdispatch.dylib                   0x0000000105fc40b4 _dispatch_call_block_and_release + 32
12  libdispatch.dylib                   0x0000000105fc5de0 _dispatch_client_callout + 20
13  libdispatch.dylib                   0x0000000105fcdef0 _dispatch_lane_serial_drain + 788
14  libdispatch.dylib                   0x0000000105fced48 _dispatch_lane_invoke + 496
15  libdispatch.dylib                   0x0000000105fdba50 _dispatch_workloop_worker_thread + 1600
16  libsystem_pthread.dylib             0x00000001d0dba7a4 _pthread_wqthread + 276
17  libsystem_pthread.dylib             0x00000001d0dc174c start_wqthread + 8
2021-06-10 11:02:10.089118+0200 myapp[1102:421886] open status SUCCESS

Build fail IOS with version 0.2.2

My app fails to build after updating previewAnyFile from 0.1.6 to 0.2.2. Any idea what is could be?

Undefined symbol: _kUTTagClassMIMEType
Undefined symbol: _kUTTagClassFilenameExtension
Undefined symbol: _UTTypeCreatePreferredIdentifierForTag
Undefined symbol: _UTTypeCopyPreferredTagWithClass
Undefined symbols for architecture arm64:
  "_kUTTagClassMIMEType", referenced from:
      CordovaPlugins.PreviewAnyFile.previewPath(_command: __C.CDVInvokedUrlCommand) -> () in PreviewAnyFile.o
      CordovaPlugins.PreviewAnyFile.previewBase64(_command: __C.CDVInvokedUrlCommand) -> () in PreviewAnyFile.o
  "_kUTTagClassFilenameExtension", referenced from:
      CordovaPlugins.PreviewAnyFile.previewPath(_command: __C.CDVInvokedUrlCommand) -> () in PreviewAnyFile.o
      CordovaPlugins.PreviewAnyFile.previewBase64(_command: __C.CDVInvokedUrlCommand) -> () in PreviewAnyFile.o
  "_UTTypeCreatePreferredIdentifierForTag", referenced from:
      CordovaPlugins.PreviewAnyFile.previewPath(_command: __C.CDVInvokedUrlCommand) -> () in PreviewAnyFile.o
      CordovaPlugins.PreviewAnyFile.previewBase64(_command: __C.CDVInvokedUrlCommand) -> () in PreviewAnyFile.o
  "_UTTypeCopyPreferredTagWithClass", referenced from:
      CordovaPlugins.PreviewAnyFile.previewPath(_command: __C.CDVInvokedUrlCommand) -> () in PreviewAnyFile.o
      CordovaPlugins.PreviewAnyFile.previewBase64(_command: __C.CDVInvokedUrlCommand) -> () in PreviewAnyFile.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Cannot open pdf on android - ionic using react. Getting the below error

Error: The old format of this exec call has been removed (deprecated since 2.1). Change to: cordova.exec(null, null, 'Service', 'action', [ arg1, arg2 ]);
at capacitorExec (capacitor-runtime.js:1975)
at execProxy (capacitor-runtime.js:2111)
at PreviewAnyFile.previewPath (capacitor-runtime.js:2760)
at callCordovaPlugin (common.ts:277)
at common.ts:53
at common.ts:14
at new Promise ()
at tryNativePromise (common.ts:13)
at getPromise (common.ts:37)
at wrapPromise (common.ts:42)
at common.ts:374
at cordova (cordova.ts:5)
at PreviewAnyFileOriginal.previewPath (index.ts:86)
at openPDF (index.tsx:27)
at onClick (index.tsx:51)
at HTMLUnknownElement.callCallback (react-dom.development.js:3945)
at Object.invokeGuardedCallbackDev (react-dom.development.js:3994)
at invokeGuardedCallback (react-dom.development.js:4056)
at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:4070)
at executeDispatch (react-dom.development.js:8243)
at processDispatchQueueItemsInOrder (react-dom.development.js:8275)
at processDispatchQueue (react-dom.development.js:8288)
at dispatchEventsForPlugins (react-dom.development.js:8299)
at react-dom.development.js:8508
at batchedEventUpdates$1 (react-dom.development.js:22396)
at batchedEventUpdates (react-dom.development.js:3745)
at dispatchEventForPluginEventSystem (react-dom.development.js:8507)
at attemptToDispatchEvent (react-dom.development.js:6005)
at dispatchEvent (react-dom.development.js:5924)
at unstable_runWithPriority (scheduler.development.js:468)
at runWithPriority$1 (react-dom.development.js:11276)
at discreteUpdates$1 (react-dom.development.js:22413)
at discreteUpdates (react-dom.development.js:3756)
at dispatchDiscreteEvent (react-dom.development.js:5889)

Can't open file

Hi there

I'm having this error in android
err file:///storage/emulated/0/Download/test.docx exposed beyond app through Intent.getData()

Do you have idea how to fix this ?

previewPath function doesn't seem to be compatible with Cordova

For some reason only preview works but previewPath does not. When I use previewPath I get the following error:

Unhandled Promise Rejection: Error: The old format of this exec call has been removed (deprecated since 2.1). Change to: cordova.exec(null, null, 'Service', 'action', [ arg1, arg2 ]);

I'm using the latest version (0.2.9) with Capacitor 3 and Ionic @ionic-native/core 5.36.0 (I don't know if that's relevant).

Let me know if you need any more information for reproduction or when I can test something for you 🙂

Bug: previewAnyFile does not work with encoded links like Firebase Storage

Ionic:
Ionic CLI : 6.12.4 (/usr/local/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/react 6.0.0-beta.5
Utility:
cordova-res : 0.15.3
native-run : 1.4.1
System:
NodeJS : v14.4.0 (/usr/local/bin/node)
npm : 6.14.5
OS : macOS Big Sur

Running an Ionic Application using React.

The URL passed to PreviewAnyFile.previewPath does not work if it's a Firebase Storage URL

I noticed another user proposing to use a decoder, however if you decode the Firebase URL and replace the %2F with a /, Firebase will not return you an image anymore.

Code:
image

Error:
image

I tried passing both a name.ext (name.jpeg) and mime type (image/jpeg). I also tried adding the extension to the Firebase URL, which doesn't break the URL, but still doesn't work in the plugin.

Cheers

Callback on clicking Done

Is it possible to add a callback when clicking Done? This will help when needing to navigate the user to alternate views and trigger response messages

iOS AR View cannot be closed

Hello,

I am using this plugin in Ionic Capacitor v6.20.1 to show usdz models in AR session. AR session works correctly but close button disappears when user tap the button and it does not close the preview.

error on xcode 11.6

While building ios app on xcode 11.6 i am getting following error

PreviewAnyFile.swift:3:48: error: use of undeclared type 'CDVPlugin'
@objc(HWPPreviewAnyFile) class PreviewAnyFile: CDVPlugin

while same plugin works for android please help.

Ionic Native Wrapper Update

Hey, first of all thank you very much for the nice update. 👍
Could you update the ionic native wrapper aswell? I need the update to display files on my S3 storage.

`cordova-plugin-androidx` dependency

Ionic suggests to remove cordova-plugin-androidx and cordova-plugin-androidx-adapter plugins.
See output of official Ionic Vscode plugin:

The plugin cordova-plugin-androidx is not required with Capacitor. This was required for Cordova Android 10 support but isnt required by Capacitor

Only plugin in our project which depends on them is now cordova-plugin-preview-any-file.
Is this needed for Cordova projects compatibility?

Pdf preview closed immediately on android

Hi, I am trying to use the library to preview a file stored locally on the device (file is saved by Capacitor.Plugins.Filesystem). Everything works just ok on iOS, file preview is displayed as expected but I have troubles on android. File preview is closed immediately. File path is 'file:///storage/emulated/0/Documents/Payslip.pdf'. I also tried different locations.

I played a bit with the Java code and ended up having a solution which is proposed here: https://inthecheesefactory.com/blog/how-to-share-access-to-file-with-fileprovider-on-android-nougat/en. This is working for me, however, this is the exact opposite from what is mentioned in the readme about file:// vs content:// uri.

Specifically, I added this part in presentFile method:

private void presentFile(Intent intent, Uri uri, String type) {
    File myFile = new File(String.valueOf(uri).replace("file://", ""));
    Uri myUri = FileProvider.getUriForFile(this.context, this.context.getApplicationContext().getPackageName() + ".provider", myFile);
    intent.setDataAndType(myUri, type);
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    this.cordova.getActivity().startActivityForResult(intent, 1);
  }

Could you please point me to a right direction what I might be doing wrong? I am absolutely new to android programming. You can find my working solution here: ufirstgroup@f783da3

Thank you.

[FIXED] Preview File from assets folder

Hi,

Using Ionic 4, how would a path for a file located in /assets directory look like?

I've tried using:

  • file://assets/filename.pdf
  • file.applicationDirectory + '/public/assets/filename.pdf' (ionic-native file plugin)

But I am getting 'The requested URL was not found on this server.'

I've checked my simulator directory and the file is there.

Thanks

ios build issues...

.....Plugins/cordova-plugin-preview-any-file/PreviewAnyFile.swift:3:48: error: cannot find type 'CDVPlugin' in scope
@objc(HWPPreviewAnyFile) class PreviewAnyFile: CDVPlugin {
^~~~~~~~~
...../Plugins/cordova-plugin-preview-any-file/PreviewAnyFile.swift:7:28: error: cannot find type 'CDVInvokedUrlCommand' in scope
func preview(_command: CDVInvokedUrlCommand){
^~~~~~~~~~~~~~~~~~~~
.../Plugins/cordova-plugin-preview-any-file/PreviewAnyFile.swift:3:2: error: only classes that inherit from NSObject can be declared @objc
@objc(HWPPreviewAnyFile) class PreviewAnyFile: CDVPlugin {
~^~~~~~~~~~~~~~~~~~~~~~~~
.../Plugins/cordova-plugin-preview-any-file/PreviewAnyFile.swift:106:1: error: cannot declare conformance to 'NSObjectProtocol' in Swift; 'PreviewAnyFile' should inherit 'NSObject' instead
extension PreviewAnyFile: QLPreviewControllerDataSource, QLPreviewControllerDelegate {
^
.../Plugins/cordova-plugin-preview-any-file/PreviewAnyFile.swift:106:1: note: do you want to add protocol stubs?
extension PreviewAnyFile: QLPreviewControllerDataSource, QLPreviewControllerDelegate {
^
.../Plugins/cordova-plugin-preview-any-file/PreviewAnyFile.swift:9:28: error: cannot find 'CDVPluginResult' in scope
var pluginResult = CDVPluginResult(
^~~~~~~~~~~~~~~
/Users/psluser/Desktop/serviceon_code/serviceon_customer/ServiceOn_CustApp/platforms/ios/Serviceon/Plugins/cordova-plugin-preview-any-file/PreviewAnyFile.swift:10:21: error: cannot find 'CDVCommandStatus_ERROR' in scope
status: CDVCommandStatus_ERROR
^~~~~~~~~~~~~~~~~~~~~~
/Users/psluser/Desktop/serviceon_code/serviceon_customer/ServiceOn_CustApp/platforms/ios/Serviceon/Plugins/cordova-plugin-preview-any-file/PreviewAnyFile.swift:100:28: error: cannot find 'CDVPluginResult' in scope
let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "CLOSING");
^~~~~~~~~~~~~~~
/Users/psluser/Desktop/serviceon_code/serviceon_customer/ServiceOn_CustApp/platforms/ios/Serviceon/Plugins/cordova-plugin-preview-any-file/PreviewAnyFile.swift:100:52: error: cannot find 'CDVCommandStatus_OK' in scope
let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "CLOSING");
^~~~~~~~~~~~~~~~~~~

warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.3.99. (in target 'OneSignal' from project 'Pods')
warning: AddressBook is deprecated. Consider migrating to Contacts instead. (in target 'Serviceon' from project 'Serviceon')
** BUILD FAILED **



``
in ios folder has only .swift file but xcode required the .m file

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.