Trouble with Corona native.showWebPopup() for local file - file not found - coronasdk

I'm trying to organize some local html files and display them using native.showWebPopup() in my Corona app. Testing on an Android device.
Right now if I put an html file directly in my main directory, I'm able to display it.
Example that works:
local options =
{
baseUrl = system.ResourceDirectory
}
native.showWebPopup("index.html",options )
However, I want to put the index.html file somewhere else. For example, in a subfolder called foo. But the app doesn't find it when I put it there. I've tried a number of different things.
Some examples that don't work:
local path = system.pathForFile( "foo/index.html", system.ResourceDirectory )
native.showWebPopup(path)
local path = system.pathForFile( "foo/", system.ResourceDirectory )
local options =
{
baseUrl = path
}
native.showWebPopup("index.html",options)
I've tried printing the path to the device log, but I'm not sure if it's what it should be or not...looks like this:
/data/data/(my app info)/files/coronaResources/foo/index.html
I can only assume that I'm pointing the app to the wrong place for the file, but I'm not sure how to fix it. Thanks for any help on this.
Also, even in the example that works above, the HTML document loads, but the images are giving me trouble...even if I put them in the same main directory. Is there something I need to do to fix that path? This didn't work:
<img border="0" src="./myimage.jpg" width="100" height="100">
and neither did this
<img border="0" src="myimage.jpg" width="100" height="100">

This seems to be working for locating/opening the html files.
local doc = "foo/index.html"
local options =
{
baseUrl = system.ResourceDirectory
}
native.showWebPopup( doc, options )

Related

Get directory path pointing to the correct folder?

I'm trying to create link for the file upload. I'm calling file upload function from .cfc file. The file should be uploaded in a different folder. Here is what I get if after this code is executed in component.cfc page:
<cfset thisPath = ExpandPath( "./" ) />
C:\\wwwroot\\myapp\\components\\
I need to go level back in myapp and open bug folder. Then in a bug folder I need to direct the path either to folder1/ documents or folder2/documents. That will depend on the form field, here is example:
<cfset folder = trim(form.type) EQ 1 "folder1" : "folder2">
The path should either point to:
C:\\wwwroot\\myapp\\bug\\folder1\\documents\\
or
C:\\wwwroot\\myapp\\bug\\folder2\\documents\\
I'm looking for a solution that will work even if I roll this code to a different server with the same directory structure. Is there a good way to achieve this in ColdFusion?

OpenLayers: Loading a TileJSON from a local file

I'm trying to implement a local copy of a TileJSON in an iOS app through Cordova. The issue I'm having is that OpenLayers doesn't seem to recognise the JSON file as valid and thus doesn't show any tiles. I have tried local and remote versions of the same TileJSON and looked at the Console Logs, the local one has a status of "error" (but no explanation as to what that error might be...).
I think the issue is down to the fact that the JSON file is being loaded using a file: URL, rather than http:. I have put the JSON file on a remote server and this not only loads fine but actually loads the tiles from the local path.
Can OpenLayers be tricked into accepting the local file as a valid JSON file? Can Cordova be forced to load local files via HTTP? I think either of these options would fix the issue.
Thanks
EDIT: Here's the code I'm using to load the TileJSON:
var mapLayer = new ol.layer.Tile({
source: new ol.source.TileJSON({
url: getPhoneGapPath() + 'tiles.json',
crossOrigin: 'anonymous'
})
});
this.map.addLayer(mapLayer);
function getPhoneGapPath() {
var path = window.location.pathname;
path = path.substr( path, path.length - 10 );
return path;
}
The getPhoneGapPath() function is used to get the path to the webroot of the Cordova app.
This is probably related to a bug in OpenLayers, https://github.com/openlayers/ol3/issues/5647. The fix will be in the next release.
Also make sure that you configure Cordova to allow access to file:// urls when the application is served from a file:// url. The equivalent option in Chrome is --allow-file-access-from-files.

Embed SWF file in firefox add-on (no SDK)

I have a problem with a firefox extension i'm developing.
I need to add an SWF file in the page. If I load it from a remote server, it works fine:
myObj2.setAttribute("data",'http://www.mySite.com/myFile.swf');
myPar1.setAttribute("value",'http://www.mySite.com/myFile.swf');
It works fine but is not accepted for the review.
so I created a resource dir in the manifest:
resource ldvswf swf/
and changed the script into:
myObj2.setAttribute("data",'resource://ldvswf/myFile.swf');
myPar1.setAttribute("value",'resource://ldvswf/myFile.swf');
but it doesn't work. The folder resource://ldvswf is ok as i tested loading an image and I see it.
The reviewer wrote me that for flash file it "requires doing so via a file: URL", but I don't know how to manage, I tested:
'file: resource://ldvswf/myFile.swf'
'file://resource://ldvswf/myFile.swf'
'file://ldvswf/myFile.swf'
'file: ldvswf/myFile.swf'
And nothing works.
Any suggestion for the right path?
Thanks a lot!
Nadia
Update: the editor wrote me:
You need a file URL that points to an actual file. If your extension is unpacked, something like the following should do:
Services.io.newFileURI(Services.io.newURI("resource://ldvswf/myFile.swf", null, null)
.QueryInterface(Ci.nsIFileURL).file)
.spec
But I don't understand how to plce it to replace:
myObj2.setAttribute("data",'http://www.mySite.com/myFile.swf');
myPar1.setAttribute("value",'http://www.mySite.com/myFile.swf');
I made some test like:
var file = Services.io.newFileURI(Services.io.newURI("resource://ldvswf/myFile.swf", null, null).QueryInterface(Ci.nsIFileURL).file).spec ;
myObj2.setAttribute("data",file);
myPar1.setAttribute("value",file);
But I get this error message:
Error: NS_NOINTERFACE: Component returned failure code: 0x80004002 (NS_NOINTERFACE) [nsIFileURL.file]
Have you tried using contentaccessible=yes in your chrome.manifest, like this:
content package_name content/ contentaccessible=yes
I tested it with an image in a local web page and it worked, don't know for SWF:
<img src="chrome://package_name/skin/window.png"/>
Another approach is to get the file URI of the chrome:// (not resource://) file like this:
function chromeToPath (aPath){
if (!aPath || !(/^chrome:/.test(aPath))){
return null; //not a chrome url
}
var Cc = Components.classes, Ci = Components.interfaces;
var spec, url, file;
var ios = Cc['#mozilla.org/network/io-service;1'].getService(Ci["nsIIOService"]);
var uri = ios.newURI(aPath, "UTF-8", null);
var crs = Cc['#mozilla.org/chrome/chrome-registry;1'].getService(Ci["nsIChromeRegistry"]);
var fph = Cc["#mozilla.org/network/protocol;1?name=file"].createInstance(Ci.nsIFileProtocolHandler);
spec = crs.convertChromeURL(uri).spec;
return spec;
}
usage:
chromeToPath('chrome://package_name/skin/window.png')
and it will return the file:// URI of the file.
If you test this, better make sure the extension is unpacked (unzipped) on install:
in install.rdf:
<em:unpack>true</em:unpack>
try breaking the line like this:
var file = Services.io.newURI("resource://ldvswf/myFile.swf", null, null).QueryInterface(Ci.nsIFileURL).file;
alert(file.path)
var file = Services.io.newFileURI(file).spec ;
alert(file)
the first alert() should give a local system path like 'c:\folder\filename...'
the second should give a file:// URI
so what do you get?
make sure you have a line in package.json:
"unpack": true,
at the same level as name, title, author etc. Note that true does not have the quotes.
(https://developer.mozilla.org/en-US/Add-ons/SDK/Tools/package_json)

Multiple input file tags with IOS 6+ on iPad/iPhone

EDIT :
I've been able to resolve this, after finding that iOS uploads every image as "image.jpg". In freeASPUpload.asp, I changed the following :
For Each fileItem In UploadedFiles.Items
filePath = path & fileItem.FileName
Set streamFile = Server.CreateObject("ADODB.Stream")
streamFile.Type = adTypeBinary
streamFile.Open
StreamRequest.Position=fileItem.Start
StreamRequest.CopyTo streamFile, fileItem.Length
streamFile.SaveToFile path & FileName, adSaveCreateOverWrite
streamFile.close
Set streamFile = Nothing
fileItem.Path = filePath
Next
To :
For Each fileItem In UploadedFiles.Items
FileName = GetFileName(path, fileItem.FileName)
fileItem.FileName = FileName
filePath = path & fileItem.FileName
Set streamFile = Server.CreateObject("ADODB.Stream")
streamFile.Type = adTypeBinary
streamFile.Open
StreamRequest.Position=fileItem.Start
StreamRequest.CopyTo streamFile, fileItem.Length
streamFile.SaveToFile path & FileName, adSaveCreateOverWrite
streamFile.close
Set streamFile = Nothing
fileItem.Path = filePath
Next
This is within the save function of the script. The GetFileName function iterates over what is in the folder already, and adds a number until it is unique. It then updates the file key to its new name. I've left an "image.jpg" file in the temp folder, so that it always finds one. That works for now.
What I've found, however, is for some reason, it flips the second photo out of the five that the form allows for..
I will try to fix that / look for others with the same issue. I've always had problems with iPhones and iPads rotating pictures, and it's never consistent.
I'm trying to grab multiple files from a mobile fleet of iPads and iPhones. Currently I have 5
<input type="file" name="fileX" accept="image/*">
This works fine in a browser (using free asp upload / classic ASP). In testing, it works with IOS, but only if I send one file. If I send more then one via the form, I get the error 'file not found'. It seems like the files aren't being sent at all.
The file not found kicks back when trying to manipulate the file via FSO.
Uploads here :
Dim Upload, fileName, fileSize, ks, i, fileKey
Set Upload = New FreeASPUpload
SaveFiles = ""
uploadsDirVar = "directory"
Upload.Save(uploadsDirVar)
ks = Upload.UploadedFiles.keys
Errors out here :
Set f=fs.GetFile(uploadsDirVar & "\" & Upload.UploadedFiles(fileKey).FileName)
Any ideas on how I can get around this? Everything I've read points towards the HTML5 multiple tag on a single input. However, in my scenario, this won't work. I'm also tying descriptions for the images to the fields based on field name, restricting the upload to 5, re-sizing the images on the action page before passing it to its final destination and attaching them to an email.
Any advice welcome, and thank you for your time!
**Edit
The issue seems to be that IOS names all uploads "image", coming from either the camera or the library. Now the problem is how to rename the image before the script attempts to upload it. From what I'm understanding, it needs to happen within the asp upload component before it places the file.
See the above edit for the answer. As for the flipped images - turns out they are flipped straight from the iPad. I checked the exif data and I'm not sure how to account for this in my system. If I find the answer, I'll post here.

Get the name of the file a storyboard is from in Corona?

I have a storyboard file and I want to reference the name of the file that the storyboard is implemented in so that I can load a configuration file of the same base name.
Here is an example that is in a file called scene001.lua
-- Called when the scene's view does not exist:
function scene:createScene( event )
local screenGroup = self.view
local json = require("json")
-- load the book definition file
local contents = textFromFile("scene001.json")
local page = json.decode(contents)
image = buildPage(page)
screenGroup:insert(image)
image.touch = onSceneTouch
end
As you can see I have to hard code the "scene001.json". I want to load a configuration file of the with the same name as the current storyboard, how can I do this dynamically?
You can use the debug library, specifically the function debug.getinfo, to retrieve information about the current file name. With a simple pattern, you can then replace the .lua extension with .json to open your custom file.
print( debug.getinfo(1,"S").short_src ) --> /path/to/scene001.lua.
I actually found a better more official way of doing this without all the regex sillyness needed to parse the path. Of the potential performance implications of using debug.getinfo().
storyboard.getCurrentSceneName()

Resources