Load local file error

Avatar

Avatar
Validate 1
Level 1
davidm87596861
Level 1

Like

1 like

Total Posts

8 posts

Correct reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile

Avatar
Validate 1
Level 1
davidm87596861
Level 1

Like

1 like

Total Posts

8 posts

Correct reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile
davidm87596861
Level 1

13-07-2017

I cant load a local file because http is only allowed.

XMLHttpRequest cannot load file:///var/mobile/... Cross origin requests are only supported for HTTP.

How can i allow to load local files in an app? Thanks, David

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Give Back
Employee
Bruce_Lefebvre
Employee

Likes

28 likes

Total Posts

62 posts

Correct reply

28 solutions
Top badges earned
Give Back
Boost 5
Boost 3
Boost 25
Boost 10
View profile

Avatar
Give Back
Employee
Bruce_Lefebvre
Employee

Likes

28 likes

Total Posts

62 posts

Correct reply

28 solutions
Top badges earned
Give Back
Boost 5
Boost 3
Boost 25
Boost 10
View profile
Bruce_Lefebvre
Employee

14-07-2017

The reason I ask is that there is a known issue which prevents local XHRs when using the WKWebView plugin: [CB-10143] Local file:// url XmlHttpRequests are not allowed in WKWebViewEngine - ASF JIRA

Answers (4)

Answers (4)

Avatar

Avatar
Give Back
Employee
Bruce_Lefebvre
Employee

Likes

28 likes

Total Posts

62 posts

Correct reply

28 solutions
Top badges earned
Give Back
Boost 5
Boost 3
Boost 25
Boost 10
View profile

Avatar
Give Back
Employee
Bruce_Lefebvre
Employee

Likes

28 likes

Total Posts

62 posts

Correct reply

28 solutions
Top badges earned
Give Back
Boost 5
Boost 3
Boost 25
Boost 10
View profile
Bruce_Lefebvre
Employee

14-07-2017

Hi David,

Have you enabled the WKWebView plugin for your app? If so, can you try creating a new app with this plugin disabled?

Avatar

Avatar
Validate 1
Level 1
davidm87596861
Level 1

Like

1 like

Total Posts

8 posts

Correct reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile

Avatar
Validate 1
Level 1
davidm87596861
Level 1

Like

1 like

Total Posts

8 posts

Correct reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile
davidm87596861
Level 1

14-07-2017

Hi. Thanks for the example.

When i try your code I get again the following error:

[Error] XMLHttpRequest cannot load file:///var/mobile/Containers/Data/Application/C500078F-1FD2-43EC-A418-BBF0686E9FBB/Library/Caches/d00a72956e898ba4b1f05bd995912e49/deea684712127650165f68d34ccf76af/folio/data.json. Cross origin requests are only supported for HTTP.

(anonymous function) (index.js:66)

It works in the Adobe preflight app, but not in our test app.

Avatar

Avatar
Give Back
Employee
Bruce_Lefebvre
Employee

Likes

28 likes

Total Posts

62 posts

Correct reply

28 solutions
Top badges earned
Give Back
Boost 5
Boost 3
Boost 25
Boost 10
View profile

Avatar
Give Back
Employee
Bruce_Lefebvre
Employee

Likes

28 likes

Total Posts

62 posts

Correct reply

28 solutions
Top badges earned
Give Back
Boost 5
Boost 3
Boost 25
Boost 10
View profile
Bruce_Lefebvre
Employee

13-07-2017

Hi David,

I've put together a simple example that shows how you can read JSON data from a local file:

GitHub - blefebvre/aemm-read-local-file: Example article that shows how you can read a local file on...

The file being read can be found here: aemm-read-local-file/data.json at master · blefebvre/aemm-read-local-file · GitHub

And the code which is reading it using an XHR is here: aemm-read-local-file/index.js at master · blefebvre/aemm-read-local-file · GitHub

When you run the app via either the aemm CLI or AEM Mobile Preflight, you will see the message from the file is displayed in the app:

Screen Shot 2017-07-13 at 3.32.16 PM.png

Hope this helps.

Avatar

Avatar
Boost 1
Level 1
bhellema
Level 1

Like

1 like

Total Posts

17 posts

Correct reply

2 solutions
Top badges earned
Boost 1
Affirm 1
View profile

Avatar
Boost 1
Level 1
bhellema
Level 1

Like

1 like

Total Posts

17 posts

Correct reply

2 solutions
Top badges earned
Boost 1
Affirm 1
View profile
bhellema
Level 1

13-07-2017

Can you paste the code that your using to try to load the content.  Also paste the URL of the content that your trying to load.