Validating file upload on use? - xpages

I want to be able to validate a file upload control BEFORE a file is uploaded. I want of course a filename to be provided but more important a filename that does not contain any spaces.
If I use conventional validation then the control is validated each time the form is saved.
Is there a way to prevent the user from selecting a file name that I do not want?

I do this in my current project. I use CSJS to check the filename prior to uploading. In this example, I am using a button that adds the file upload control and several other fields to a new document. You could change this to check for a specific filename and check for spaces. My upload control is named "fileUpload3", yours will be what you name it.
var x=document.getElementById("#{id:fileUpload3}").value;
if (x==null || x=="" || x.slice(-3) != "pdf")
{
alert("Store Transfer details in PDF format are required.");
return false;
}

Related

Is there a reliable way to detect file changes with PnP (nodejs) on Sharepoint?

Im am using PnP nodejs to do certain tasks triggered by SP workflows. To detect whether an uploaded file has changed it's content - I have to retrieve file size or a content hash form the new upload.
Unfortunately the item object delivered with ".getItem()" does not provide any hash or file size (with file.Modified it is not possible not reliably detect a file change):
sp.web
.getFileByServerRelativePath(relativeUrl) //Eg. /Documents/a/file.txt
.getItem()
.then((file) => {...})
Any suggestions to retrieve this with PnP?
Or, is there a better and reliable way to detect whether a s specific file has changed on Sharepoint with PnP?
You could retrieve the file size use file.Length property, like the below:
sp.web
.getFileByServerRelativePath("/sites/test/Shared Documents/a.txt")
.get()
.then(file=>{
console.log(file.Length)
});

In Azure Logic App ,how to create a file name that has Video Title and Video ID in the (Create File action step)?

I have created a 1st Logic app : that allows a user to upload a .mp4 media file into a folder on OneDrive, and the logic app checks to see if there is new file on that OneDrive folder. If there is new file, it will trigger the logic app and Index the video onto https://www.videoindexer.ai/.
2nd - Logic App : After the video is indexed to https://www.videoindexer.ai/ , I want the user to pick language(s) from the custom web page that I have created, for caption translation. Once the user choose the language(s) they click on "submit" and this will send the data(languages) to my 2nd logic app URL end-point, and trigger my second logic app(shown below) and get the captions based on the user's selection of languages. Finally, it will then output those caption files on to a OneDrive folder.
Right now, the caption file names are in format of : videoID_language.vtt (Example: e0b3483dd1_en-US.vtt). The problem with this format is that, lets say we have multiple videos, the user will find it hard to match which caption file belongs to which video. So that is why I am looking to add video title name, so that they know which caption file are for which video.
My question is: How can I also add video Name to the file as well? So lets say I have video tile such as "AzureFunction". I want my VTT file name to look like this AzureFunction_e0b3483dd1_en-US.vtt
What I tried to do was change the file name query
From this:
concat(triggerOutputs()['body']['videoId'],'',item(),'.vtt')
TO this:
concat(triggerOutputs()['body']['name']['videoId'],'',item(),'.vtt')
But it gives an error because, it does't know the 'name'.
How to include the video name as part of my title?
Here is the 2nd logic app workflow, that I am using to create the file:
What I tried to do was change the file name query From this:
concat(triggerOutputs()['body']['videoId'],'',item(),'.vtt') TO this: concat(triggerOutputs()['body']['name']['videoId'],'',item(),'.vtt')
triggerOutputs() returns a JSON object. Based on the FIRST code, that JSON structure is body (object) > videoId (property). Changing it to your SECOND version indicates that the structure is body (object) > name (object) > videoId (property). It seems unlikely that the name property has a videoId subproperty.
More importantly, you said the error indicated "it doesn't know the name", which would indicate that there is no name property on the triggerBody. You say you tried to concat the video name - how are you getting the name of the video? Or is that your question? Since the triggerBody is an HTTP request, it is not clear that the video name is part of the HTTP request. If you have the ID, is there another Video Indexer action that you could use to retrieve the Name?

How to compare email attachment extension while reading attachments in azure logic app?

i am able to iterate through email attachments in azure logic app. i must have to compare attachment extension before further processing. i have been trying with content type parameter and passing values like '.xml' or 'xml' or 'application/xml'. none of them worked well.
what would be best practice to achieve this?
If you want to check the filename extension of an attachment, create a condition using one of our workflow functions - http://aka.ms/logicappsdocs - like #endswith()
You can do this all in the designer as follows (I opened a condition and set "Attachment Name" to ends with xml
Also be sure you set your trigger to include the attachment data

Can't migrate RichText to RichText in XPages

I have an old Notes Client application. On the form are two RichText fields that hold attachments. JPG's, PDF's, whatever. The document also contains a unique key and other meta-data.
What I want to do is migrate from having multiple attachments on a document to a new document for each attachment. I've never done much with embedded objects and even less with MIME.
I'm currently working in XPages Java but could go to LotusScript if need be.
I was working with this snippet:
List<EmbeddedObject> docPicture = this.getFileAttachments(doc, "picture");
List<EmbeddedObject> docPDF = this.getFileAttachments(doc, "pdf");
for (EmbeddedObject eoPic : docPicture) {
picCount++;
Document newDoc = currentDatabase.createDocument();
newDoc.replaceItemValue("form", "fm_file");
newDoc.replaceItemValue("uploadToken", doc.getItemValueString("barCodeHuman"));
newDoc.replaceItemValue("fileName", eoPic.getName());
newDoc.replaceItemValue("size", eoPic.getFileSize());
fileName = eoPic.getName();
fileType = fileName.substring(fileName.length() - 3);
newDoc.replaceItemValue("type", this.getMIMEType(fileType));
// Extract Attachment and Add To Attachment Document
InputStream attachInputStream = eoPic.getInputStream();
Stream attachStream = session.createStream();
attachStream.setContents(attachInputStream);
MIMEEntity attachField = newDoc.createMIMEEntity("attachment");
MIMEHeader attachHeader = attachField.createHeader("content-disposition");
attachHeader.setHeaderVal("attachment;filename=\"" + eoPic.getName() + "\"");
attachField.setContentFromBytes(attachStream, this.getMIMEType(fileType), MIMEEntity.ENC_IDENTITY_BINARY);
Note I'm using the OpenNTF API but could go back to the lotus objects if need be.
Anyway - this almost worked. I got my documents - 1 per attachment. But when going into the field "attachment" in the document propertied it's not a RichTextField it's a MIME something. that's causing me probably with the next phase of my project. The RichTextDocuments work fine but not the MIME ones.
this is a 1 time migration need so any thoughts on how I can end up with RichTextFields would be appreciated. Thanks!!
try to not involve mime entities at all.
as Oliver said, check your target richText field on the form does not have the 'store contents as mime' checked.
you could even use a richText lite field and restrict it to attachments.
I think you might be using the MIMEEntity method setContentsFromStream because you want to directly move the attachment from doc to doc?
if you want to move using just RichText embedded objects (no mime entity involvement) you need to extract the embeddedObject using .extractFile to the file system first.
Then using the RichTextItem that you create on the new doc (instead of create mime entity) you can use rti.embedObject to attach the file you extracted. (probably best to delete the temporary extract file after successful migration), see the designer help for an example of the parameters required for embedding attachments.
when extracting the file to file system you could extract it to the JVM's temporary directory, the file on the file system needs to have the same file name that you want it to have when attached to the new document.
for this reason you can't really use File.createTemporaryFile() because your temp file name will have random characters in it. instead you
you can get the temp directory with
System.getProperty("java.io.tmpdir")`
and the use that in your extract filepath.
another thing to check before starting processing, is the current notesSession's isConvertMIME setting, if to source field is mime, session.isConvertMIME == true will convert the field to richText when loading the doc. I think in xpages it is false by default, though I don't think it will affect you because I think your source attachments are already richText but for someone reading this and using mime source field it would be important to note. also if you change this using setConvertMIME, be sure to change it back to what it was when you finish your processing.

How do I manage Attachments (View / Delete)

I am able to add a file upload control to my page and add attachments. But how do I manage them? View , delete?
I added a computed field to my xpage and make the attachments field the source and set the field as HTML. I get a bunch of entries like (See attached file: abc.pdf). But that does not seem to do what I want.
Is there an easy way to manage these attached files?
Bind a file download control to the same data the upload control is bound to. One of the attributes this component supports is a boolean for whether to allow deletion. You can also choose which attributes of each file it displays (MIME type, size, etc.).
What is wrong with having an repeat control repeat over the filenames and generate links directly to those files where on the links there are event handlers which do a remove or view ?

Resources