Get file url in javascript
--UPDATE-- Show So I am attempting to create a file previewer that allows someone to upload files with on the front end, access the browser files as a blob, and preview them in an iframe. MUST BE ABLE TO PREVIEW ALL OPEN DOCUMENT FILES My current issue is that viewer.js (http://viewerjs.org/instructions/) doesn't seem to work with blob files. This was the closest information I got..https://github.com/kogmbh/ViewerJS/issues/230 Any ideas on a way to have this work with all open document files? Plugin recommendations? Current Code below..
--UPDATE #2-- So I got it figured out. I had to use a different plugin. webODF instead... I should be able to cobble together a decent enough solution now.
This snippet will get the filename from the url. The filename is the last part of the URL from the last trailing slash. For example, if the URL is http://www.example.com/dir/file.html then file.html is the file name. Explanation
This declares the url variable and adds the current pathname as its value.
substring (method) - extract characters from start (parameter). url is the stringObject url.substring(start) lastIndexOf (method) - position of last occurrence of specified string value, in this case the ‘/’ Add one to lastIndexOf because we do not want to return the ‘/’ Full snippet
The The URL lifetime is tied to the To release an object URL, call Note: This feature is available in Web Workers Note: This feature is
not available in Service Workers due to its potential to create memory leaks. A A string containing an object URL that can be used to reference the contents of the specified source ExamplesUsage notesMemory management Each time you call Browsers will release object URLs automatically when the document is unloaded; however, for optimal performance and memory usage, if there are safe times when you can explicitly unload them, you should do so. Using object URLs for media streams In older versions of the Media Source specification, attaching a stream to a Warning: If you still have code that relies on Specifications
Browser compatibilityBCD tables only load in the browser See alsoHow do I get the URL of a JavaScript file?To retrieve just the URL as a string, the read-only document. URL property can be used. Sun reference: Do not use location as a property of the document object; use the document. URL property instead.
How do I find the URL for an uploaded file?Answers. string UploadDir=Server. MapPath("~/UploadFolder"); strFileName = Path. Combine( UploadDir,FileUpload1.
What is Objecturl?Blob URL/Object URL is a pseudo protocol to allow Blob and File objects to be used as URL source for things like images, download links for binary data and so forth. For example, you can not hand an Image object raw byte-data as it would not know what to do with it.
How do you split a URL?var newURL="http://www.example.com/index.html/homePage/aboutus/"; console. log(newURL); var splitURL=newURL. toString(). split("/"); console.
|