{"_id":"57b557f0d3092517007cfacb","project":"54523fec04160008005b1cc8","user":"54523f0604160008005b1cc0","category":{"_id":"57b557f0d3092517007cfac4","project":"54523fec04160008005b1cc8","__v":0,"version":"57b557f0d3092517007cfac3","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2014-11-13T07:05:09.147Z","from_sync":false,"order":0,"slug":"rollmyfile-javascript-api","title":"rollMyFile JavaScript API"},"githubsync":"","version":{"_id":"57b557f0d3092517007cfac3","project":"54523fec04160008005b1cc8","__v":2,"createdAt":"2016-08-18T06:38:40.018Z","releaseDate":"2016-08-18T06:38:40.018Z","categories":["57b557f0d3092517007cfac4","57b557f0d3092517007cfac5","59c4d73c5237e3003c4532c3"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"2.0.0","version":"2.0"},"__v":0,"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2014-11-13T08:21:04.098Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"never","params":[],"url":""},"isReference":false,"order":5,"body":"Key method of rollMyFile API – given the URL to download a file and open it online with one of the applications on rollApp.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"rollMyFile.openFileByUrl(\\\"http://www.example.com/documentation/overview.docx\\\");\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nWith this call application will open in a separate window with the file loaded into it.\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Pop-up Blocker\",\n  \"body\": \"To prevent pop-up blocker from interfering with application launch this method has to be called from an event handler for click or key press.\\n\\nMore about pop-up blocker [from Mozilla developers][0].\\n\\n[0]: https://support.mozilla.org/en-US/kb/pop-blocker-settings-exceptions-troubleshooting\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Parameters\"\n}\n[/block]\n\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Paramater\",\n    \"h-1\": \"Description\",\n    \"0-0\": \"url\",\n    \"1-0\": \"options\\n*optional*\",\n    \"0-1\": \"URL for the file to open.\\n\\nThis URL has to be accessible for rollApp to download the file for editing.\",\n    \"1-1\": \"Following are the available options:\\n\\n* name (*optional*) – explicit name of the file being opened\\n* app (*optional*) – id of the app to open the file\",\n    \"2-1\": \"Called when attempt to open a file failed for any reason.\",\n    \"3-1\": \"Called after the file was opened successfully.\",\n    \"3-0\": \"onsuccess\\n*optional*\",\n    \"2-0\": \"onerror\\n*optional*\"\n  },\n  \"cols\": 2,\n  \"rows\": 4\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Usage\"\n}\n[/block]\nThe application to open the file is determined using file name deduced from the URL. However, that would not work, if URL does not contain name of the file. In this case you can explicitly pass name of the file to *openFileByUrl* like this:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"rollMyFile.openFileByUrl(\\\"http://www.example.com/file/12345678\\\",\\n                         {\\\"name\\\": \\\"overview.docx\\\"});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nThe example above will use default association of type of file to application, which is capable of handling such files. For instance, .docx files open in LibreOffice and .txt files open in Gedit. If you want to open .txt in LibreOffice writer, you can explicitly specify, which application to use:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"rollMyFile.openFileByUrl(\\\"http://www.example.com/file/12345678\\\",\\n                         {\\\"name\\\": \\\"overview.docx\\\",\\n                          \\\"app\\\": \\\"lowriter\\\"});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nFor better visibility into the result of the operation, for example, to show custom error message, when opening a file fails, you can supply `onerror` and `onsuccess` callbacks to *openFileByUrl*.","excerpt":"","slug":"rollmyfile-js-openfilebyurl","type":"fn","title":"openFileByUrl(url, options, onerror, onsuccess)"}

openFileByUrl(url, options, onerror, onsuccess)


Key method of rollMyFile API – given the URL to download a file and open it online with one of the applications on rollApp. [block:code] { "codes": [ { "code": "rollMyFile.openFileByUrl(\"http://www.example.com/documentation/overview.docx\");", "language": "javascript" } ] } [/block] With this call application will open in a separate window with the file loaded into it. [block:callout] { "type": "warning", "title": "Pop-up Blocker", "body": "To prevent pop-up blocker from interfering with application launch this method has to be called from an event handler for click or key press.\n\nMore about pop-up blocker [from Mozilla developers][0].\n\n[0]: https://support.mozilla.org/en-US/kb/pop-blocker-settings-exceptions-troubleshooting" } [/block] [block:api-header] { "type": "basic", "title": "Parameters" } [/block] [block:parameters] { "data": { "h-0": "Paramater", "h-1": "Description", "0-0": "url", "1-0": "options\n*optional*", "0-1": "URL for the file to open.\n\nThis URL has to be accessible for rollApp to download the file for editing.", "1-1": "Following are the available options:\n\n* name (*optional*) – explicit name of the file being opened\n* app (*optional*) – id of the app to open the file", "2-1": "Called when attempt to open a file failed for any reason.", "3-1": "Called after the file was opened successfully.", "3-0": "onsuccess\n*optional*", "2-0": "onerror\n*optional*" }, "cols": 2, "rows": 4 } [/block] [block:api-header] { "type": "basic", "title": "Usage" } [/block] The application to open the file is determined using file name deduced from the URL. However, that would not work, if URL does not contain name of the file. In this case you can explicitly pass name of the file to *openFileByUrl* like this: [block:code] { "codes": [ { "code": "rollMyFile.openFileByUrl(\"http://www.example.com/file/12345678\",\n {\"name\": \"overview.docx\"});", "language": "javascript" } ] } [/block] The example above will use default association of type of file to application, which is capable of handling such files. For instance, .docx files open in LibreOffice and .txt files open in Gedit. If you want to open .txt in LibreOffice writer, you can explicitly specify, which application to use: [block:code] { "codes": [ { "code": "rollMyFile.openFileByUrl(\"http://www.example.com/file/12345678\",\n {\"name\": \"overview.docx\",\n \"app\": \"lowriter\"});", "language": "javascript" } ] } [/block] For better visibility into the result of the operation, for example, to show custom error message, when opening a file fails, you can supply `onerror` and `onsuccess` callbacks to *openFileByUrl*.