File Upload Control in Domino - file-upload

I need to post a file to Domino Server from a PhoneGap Application.
Here is the PhoneGap File Transfer example
// !! Assumes variable fileURI contains a valid URI to a text file on the device
var win = function(r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
}
var fail = function(error) {
alert("An error has occurred: Code = " = error.code);
}
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName=fileURI.substr(fileURI.lastIndexOf('/')+1);
options.mimeType="text/plain";
var params = new Object();
params.value1 = "test";
params.value2 = "param";
options.params = params;
var ft = new FileTransfer();
ft.upload(fileURI, "http://some.server.com/upload.php", win, fail, options);
//This is a PHP example - Domino would be like
// ft.upload(fileURI, "http://some.server.com/database.nsf/attachmentForm? createDocument", win, fail, options);
Does anyone know what needs to be done in Domino to get the file attachment that is being posted?

The easiest thing to do would be to create a form in Domino containing a File Upload control. You should be able to open the Domino form with a browser and see the generated html form that would normally be used. In there you will find all the info you need. This is of course dependent on the ft.upload method acting like an http multipart/form-data POST.

Related

non-invocable member 'File' cannot be used like a method error message- what am I missing?

I have a Blazor Application which had files uploaded to a upload folder on the web server. I am in the process of trying to figure out the code to download an uploaded file in the browser for retrieval and viewing. Right now the code is as below (the download part from code examples on the internet)
public void FileDetailsToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args)
{
string path = null;
string uploads = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "wwwroot\\uploads");
path = uploads + "\\" + SelectedFileName;
if (args.Item.Text == "Delete")
{
//Code for Deleting goes here
//UploadRef.Remove();
if (System.IO.File.Exists(path))
{
System.IO.File.Delete(path);
}
FileDetailsService.FileDetailsDelete(SelectedFileId); //NavigationManager.NavigateTo($"/ServiceRequestNotes/servicerequestnoteadd");
NavigationManager.NavigateTo($"/ServiceRequests/serviceRequestsaddedit2/{Id}", forceLoad: true);
}
else
{
// its a download
IFileProvider provider = new PhysicalFileProvider(uploads);
IFileInfo fileinfo = provider.GetFileInfo(path + SelectedFileName);
var readStream = fileinfo.CreateReadStream();
var mimeType = "application/pdf";
return File(readStream, mimeType, SelectedFileName);
}
}
On the last statement I am a getting the following error message
non-invocable member 'File' cannot be used like a method error message
What am I missing or do I need to change or add to have the output from the readstream render to the browser?
The blazor application is a blazor server app not WASM. It does not make use of API controllers.
Any advice?
This is a void method. You can't return anything at all. Also, if you're trying to instantiate a File object, you'd have to use the new keyword.

MobileFirst 7.0 image upload and javascript adapter parameters size limit

It seems that there is already a similar question on so and we meet with it indeed.
We are calling adapters and sending encoded base64 strings to the backend. All things works fine with tiny pictures less than 1Mb. But if the image size is larger (eg. 4Mb, just a ordinary Photo from the end-user's iPhone album), it stucked with adapter invoking errors. I also find clues after debugging that, in condition with uploading large image the adapter will never step into the backend business logic but in the condition the tiny pics can.
Some of the code snippets could be like below:
var base64Str = "";
var reader = new FileReader();
reader.onload = function(e) {
base64Str = e.target.result;
preview.setAttribute('src', base64Str );
uploadImage(picUuid, base64Str);
}
//calling the HTTP image upload adapter
function uploadImage(uuid, base64Data){
WL.Logger.debug("base64Data:" + base64Data);
var invocationData = {
adapter : 'ImageUploadAdapter',
procedure : 'uploadImage',
parameters : [uuid, base64Data]
};
WL.Client.invokeProcedure(invocationData, {
onSuccess : uploadImageSuccess,
onFailure : uploadImageFailure,
});
}
function encodeImageFileAsURL() {
var filesSelected = document.getElementById("inputFileToLoad").files;
if (filesSelected.length > 0) {
var fileToLoad = filesSelected[0];
var fileReader = new FileReader();
fileReader.onload = function(fileLoadedEvent) {
var srcData = fileLoadedEvent.target.result; // <--- data: base64
var newImage = document.createElement('img');
newImage.src = srcData;
alert(srcData);
document.getElementById("imgTest").innerHTML = newImage.outerHTML;
alert("Converted Base64 version is " + document.getElementById("imgTest").innerHTML);
console.log("Converted Base64 version is " + document.getElementById("imgTest").innerHTML);
uploadImage(srcData);
}
fileReader.readAsDataURL(fileToLoad);
}
}
//calling the HTTP image upload adapter
function uploadImage(srcData){
WL.Logger.debug("srcData:" + srcData);
var invocationData = {
adapter : 'ImageUploadAdapter',
procedure : 'uploadImage',
parameters : [srcData]
};
WL.Client.invokeProcedure(invocationData, {
onSuccess : uploadImageSuccess,
onFailure : uploadImageFailure,
});
}
MobileFirst Platform 7.0 introduced Java adapters in addition to the existing JavaScript adapters.
With Java adapters there is no such limitation for the file sizes that can be operated on when using JavaScript adapters and data can be handled as Binary rather than encoded to base64, etc.
In other words, there is no multi-part support in JavaScript adapters, whereas in Java adapters (that are based on the JAX-RS specifications) you can.
You can read more about it here:
https://developer.ibm.com/mobilefirstplatform/documentation/getting-started-7-0/server-side-development/adapter-framework-overview/

OneDrive REST API get files without folderID

I'm trying to use the oneDrive REST API to get files in a specific folder.
I have the path to the folder (For example "myApp/filesToDownload/", but don't have the folder's oneDrive ID. Is there a way to get the folder ID or the files in the folder with the REST API?
The only way I see to get it is by using https://apis.live.net/v5.0/me/skydrive/files?access_token=ACCESS_TOKEN
to get the list of folders in the root, and then splitting the path string on "/" and looping on it, each time doing a GET https://apis.live.net/v5.0/CURRENT_FOLDER/files?access_token=ACCESS_TOKEN request for each hierarchy.. I would prefer to avoid doing all those requests because the path may be quite long..
Is there a better/simpler way of getting the files of a specific folder?
Thanks
As Joel has pointed out, Onedrive API supports path based addressing also (in addition to ID based addressing). So you don't need the folder ID. You can use the Onedrive API (api.onedrive.com) for getting the files/folders of a specific folder as follows:
String path = "path/to/your/folder"; // no '/' in the end
HttpClient httpClient = new DefaultHttpClient();
// Forming the request
HttpGet httpGet = new HttpGet("https://api.onedrive.com/v1.0/drive/root:/" + path + ":/?expand=children");
httpGet.addHeader("Authorization", "Bearer " + ACCESS_TOKEN);
// Executing the request
HttpResponse response = httpClient.execute(httpGet);
// Handling the response
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
StringBuilder builder = new StringBuilder();
for (String line = null; (line = reader.readLine()) != null;) {
builder.append(line).append("\n");
}
JSONTokener tokener = new JSONTokener(builder.toString());
JSONObject finalResult = new JSONObject(tokener);
JSONArray fileList = null;
try{
fileList = finalResult.getJSONArray("children");
for (int i = 0; i < fileList.length(); i++) {
JSONObject element = (JSONObject) fileList.get(i);
// do something with element
// Each element is a file/folder in the form of JSONObject
}
} catch (JSONException e){
// do something with the exception
}
For more details see here.

How to check & confirm if dropzone is actually sending file to server

I am using dropzonejs and using following code to initialize dropzone:
var myDropzone = new Dropzone("div#myId", { url: "/file/post"});
On the server side, I am using expressjs\nodejs & using following code:
fs.readFile(req.files.displayImage.path, function (err, data) {
// ...
var newPath = __dirname + "/uploads/uploadedFileName";
fs.writeFile(newPath, data, function (err) {
res.redirect("back");
});
});
problem is req.files is always coming as undefined.
I want to know when we upload a file, is there a way through developertoolbar to check the payload & confirm whether file is been sent or not?

Reading email via thunderbird extension in html format

I am using the
function MsgHdrToMimeMessage(aMsgHdr, aCallbackThis, aCallback,
aAllowDownload, aOptions) {
method from http://mxr.mozilla.org/comm-central/source/mailnews/db/gloda/modules/mimemsg.js#171 to read the selected email via thunderbird extension. This method works fine and the only trouble is that it gives the plain text message by stripping all the html from the message.
How to get a html version of the message instead?
As I know you cannot access to the whole body (with mail and html tags). You have the functions and attributes of the XPCOM scriptable interface nsIMsgDbHdr.
I have an add-on which sends mail. I read the whole mail body with the help of the following code snippet. As you can see I read the whole mail from the disk and loaded its content into a variable. You can also use it to read the full mail body.
function SendMailNow(aMsgDBHdr) {
var aMsgURI = aMsgDBHdr.folder.getUriForMsg(aMsgDBHdr);
var msgWindow = Components.classes["#mozilla.org/messenger/msgwindow;1"]
.createInstance();
msgWindow = msgWindow.QueryInterface(Components.interfaces.nsIMsgWindow);
var msgStream = Components.classes["#mozilla.org/network/sync-stream-listener;1"]
.createInstance();
msgStream = msgStream.QueryInterface(Components.interfaces.nsIInputStream);
var aMsgService = messenger.messageServiceFromURI(aMsgURI);
var scriptInputStream = Components.classes["#mozilla.org/scriptableinputstream;1"]
.createInstance();
scriptInputStream = scriptInputStream
.QueryInterface(Components.interfaces.nsIScriptableInputStream);
scriptInputStream.init(msgStream);
try {
aMsgService.streamMessage(aMsgURI, // uri of message to stream
msgStream, // a stream listener listening to the message
msgWindow, // a nsIMsgWindow for progress and status feedback
null, // a nsIUrlListener that is notified when url starts and stops
false, // it will create a stream converter from message rfc2822 to
null // Header added to the URI. e.g., header=filter
);
} catch (ex) {
}
// Creating content
var content = "";
while (scriptInputStream.available()) {
content = content + scriptInputStream.read(512);
if (content.match(/\r\n\r\n/) || content.match(/\n\n/)) {
if (sendMail(content, aMsgDBHdr.messageId)) {
log("SEND_DONE\t" + aMsgDBHdr.messageId + "\t"
+ aMsgDBHdr.subject);
} else {
log("SEND_FAILED\t" + aMsgDBHdr.messageId + "\t"
+ aMsgDBHdr.subject);
}
}
}
}
I hope this will help you!