I just tried to many code from internet to open automatically .doc which are attached in PDF but i get this : "Cannot open type of application/msword"
I tried this:
var oDoc = openDataObject("image.doc"); console.println(oDoc.path);
I tried to find another function which are specify the type of the document and to can open it in Microsoft Word!
Regards
The openDataObject method will throw an exception instead of returning a Doc if any of the following conditions are true:
The document that this method is being called for does not contain the requested embedded data object.
The data object is not a PDF document.
Permissions forbid opening attachments by means of JavaScript.
Instead of openDataObject which tells the viewer to open the file, use exportDataObject with the launch parameter. 0 will prompt the user to save the file, 1 will save the file and launch it.
this.exportDataObject({ cName: "image.doc", nLaunch: 1 });
Related
I have following simple code for downloading file.
let text = 'download'
function make(){
const data = new Blob([text],{ type: 'type: "text/plain"' })
document.querySelector('a').download = 'untitle'
document.querySelector('a').href = window.URL.createObjectURL(data);
}
make()
<a download>Download</a>
Broswer (in chrome not sure about other broswer) will automatically specify the number for the second or more time of downloading a same name file.
Example:
first time download: untitle.text
second time download: untitle(1).text
......
Is it possible to prevent the browswer of this behavior from happening ?
Thanks
You could try in https://jsfiddle.net/yapb2xus/1/
You just can't, that's the default behavior for most of the browsers and almost all OSes because you can't have two files with the same name.
Since chrome (and firefix I think) automatically save the file in a default path, in the first time the file untitle.text will not exist and will be saved with original name. At second tryz the file will exist on default download path, so the browser automatically add a sufix to it.
What you can try is to create your own sequence, adding a timestamp or something else to the name at every click on the link.
I have a list of links, where each link corresponds to a different file that can be PDF, DOC, XLS, etc. obtained through a viewer on a jsp page. I have the link and the code for the file (documentId), but the way I'm doing it only downloads the last file in the list:
// File 1
var url1 = "https://site.site.net/servlet/DocumentServlet?documentId=123456789&action=viewUncontrolledCopy#toolbar=0&navpanes=0&scrollbar=0";
// File 2
var url2 = "https://site.site.net/servlet/DocumentServlet?documentId=987654321&action=viewUncontrolledCopy#toolbar=0&navpanes=0&scrollbar=0";
window.location.assign (url1);
setTimeout (20000);
window.location.assign (url2);
I have already searched and could not find something that completely do what I need.
Try with the window.open command
// File 1
var url1 = "https://site.site.net/servlet/DocumentServlet?documentId=123456789&action=viewUncontrolledCopy#toolbar=0&navpanes=0&scrollbar=0";
// File 2
var url2 = "https://site.site.net/servlet/DocumentServlet?documentId=987654321&action=viewUncontrolledCopy#toolbar=0&navpanes=0&scrollbar=0";
window.open(url1);
window.open(url2);
This will download the files by opening two new windows thus maintaining the first page open and the javascript running
Check here: https://www.w3schools.com/jsref/met_loc_assign.asp
Location assign navigates to a new page. This means that the rest of your javascript is not executed and only the first navigation occurs.
I have created a file as part of a script on a network drive and i am trying to make it hidden so that if the script is run again it should be able to see the file and act on the information contained within it but i am having trouble doing this. what i have so far is:
function doesRegisterExist(oFs, Date, newFolder) {
dbEcho("doesRegisterExist() triggered");
sExpectedRegisterFile = newFolder+"\\Register.txt"
if(oFs.FileExists(sExpectedRegisterFile)==false){
newFile = oFs.OpenTextFile(sExpectedRegisterFile,8,true)
newFile.close()
newReg = oFs.GetFile(sExpectedRegisterFile)
dbEcho(newReg.Attributes)
newReg.Attributes = newReg.Attributes+2
}
}
Windows Script Host does not actually produce an error here and the script runs throgh to competion. the only guides i have found online i have been attempting to translate from VBscript with limited success.
variables passed to this function are roughly declared as such
var oFs = new ActiveXObject("Scripting.FileSystemObject")
var Date = "29-12-2017"
var newFolder = "\\\\File-Server\\path\\to\\folder"
I know ActiveX is a dirty word to a lot of people and i should be shot for even thinking about using it but it really is a perfect fit for what i am trying to do.
Please help.
sExpectedRegisterFolder resolves to \\\\File-Server\\path\\to\\folder\\Register which is a folder and not a file.
I get an Error: file not found when I wrap the code into a try/catch block.
I tested the code on a text file as well, and there it works.
So you're either using the wrong method if you want to set the folder to hidden.
Or you forgot to include the path to the text if you want to change a file to hidden.
( Edit: Or if Register is the name of the file, add the filetype .txt ? )
If you change GetFile to GetFolder as described in https://msdn.microsoft.com/en-us/library/6tkce7xa(v=vs.84).aspx
the folder will get hidden correctly.
I've a DataSnap server method
function TServerMethods.GetFile(filename): TStream
returning a file.
In my test case the file is a simple .PDF.
I'm sure this function works fine, as I'm able to open files on ObjectiveC client side app's where I've used my own http call to the DataSnap method (no Delphi proxy).
The stream is read from ASIHttpRequest object and saved as local file, then loaded and regulary shown in standard pdf reader.
I do not kown how exactly ASIHttpRequest manages the returned data.
But on JavaScript client side where I use standard
stream = ServerMethods().GetFile('test.pdf')
JavaScript function, as provided from DataSnap proxy itself, I do not figure out how to show the .pdf data to the user.
Using
window.open().document.write(stream);
a new browser window opens with textual raw data ( %PDF-1.5 %âãÏÓ 1 0 obj << /Type /Catalog /Pages 2 0 R …..)
With
window.open("data:application/pdf;base64," +stream);
I get an empty new browser page.
With
window.open("data:application/pdf," +stream);
or
document.location = 'data:application/pdf,'+encodeURIComponent(serverMethods().GetFile('test'));
I get an new browser page with pdf empry reader and alert “This PDF document could not be displayed correctly”
Nothing changes adding:
GetInvocationMetadata().ResponseContentType := 'application/pdf';
into the DataSnap function.
I've no other ideas...
EDIT
The task is for a general file download, not only PDF. PDF is a test only. GetFile have to manage .pdf, .xlsx, .docx, .png, .eml, etc...
Your server side code works as expected once you set the ResponseContentType. You can test this by calling the method directly from a browser. Change the class name to match the one you're using:
http://localhost:8080/datasnap/rest/TServerMethods1/GetFile/test.pdf
I'm sure there's a way to display the stream properly on the browser side, but I'm not sure what that is. Unless you're doing something special with the stream, I'd recommend getting the document directly or using a web action and getting out of the browser's way. Basically what mjn suggested.
I can think of a couple of solutions.
1) A quick way would be to allow access to the documents directly.
In the WebFileDispatcher, add a WebFileExtension. Select .pdf and it will fill in the mime type for you. Assuming your pdf documents are in the "docs" folder, the url might look like this:
http://localhost:8080/docs/test.pdf
2) I would probably add an action on the web module. It's a little more involved, but it also gives me more control.
Using this url:
http://localhost:8080/getfile?filename=test.pdf
And code like this in the web action handler (no checking or error handling). The Content-Disposition header suggests a file name for the downloaded file:
procedure TWebModule1.WebModule1GetFileActionAction(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
lStream: TMemoryStream;
lFilename: string;
begin
lFilename := Request.QueryFields.Values['filename'];
lStream := TMemoryStream.Create;
lStream.LoadFromFile('.\Docs\' + lFilename);
lStream.Position := 0;
Response.ContentStream := lStream;
Response.ContentType := 'application/pdf';
Response.SetCustomHeader('Content-Disposition',
Format('attachment; filename="%s"', [lFilename]));
end;
Is it possible to develop HTML5/JavaScript/Jquery/REST code to upload a file to SPO 2013 Document Library?
If so, is it possible to do some validation, error handling and business rules? For example:
Handle errors
Restrict file type
Rename the file during upload to a unique sequence
Set Doc library content type metadata columns
If so, is it possible to do all of this with NAPA?
I found this:
http://blogs.msdn.com/b/uksharepoint/archive/2013/04/20/uploading-files-using-the-rest-api-and-client-side-techniques.aspx?wa=wsignin1.0&CommentPosted=true#commentmessage
Yes, I'm actually doing that right now (uploading images to a document library - and changing property values of that document once its been successfully uploaded) I found this link very useful:
http://technet.microsoft.com/en-us/dn769086(v=office.12)
I had an issue with the "fileCollectionEndPoint" and the "serverRelativeUrlToFolder" variables, I changed the value to:
var serverRelativeUrlToFolder = 'YOUR_DOCUMENT_LIBRARY';
var fileCollectionEndPoint = String.format("../../_api/web/getfolderbyserverrelativeurl('{0}')/files/add(overwrite=true, url='{1}')?#target='{2}'", serverRelativeUrlToFolder, fileName, _hostweburl);
That's just what worked for me - YMMV, the TechNet code may work OOB for you.
Handling the restriction of filetypes... you can use a client side method of checking the value of the file input element and checking against an array of extension that are acceptable... Here is a fiddle:
http://jsfiddle.net/madkidflash/vah3kc0p/