Retrieve uploaded relativePath file on server side - jsf

I'm using fileUpload from Primefaces (JSF framework) based on jQuery-File-Upload. I'm trying to make this component supporting drag&drop folder thanks to new File API of Firefox or Chrome. https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/webkitdirectory#Example So far, I've been able to make it happen thanks to passthrough attribute.
One of the interesting feature is "webkitRelativePath" allowing to know the relative path of an uploaded file.
I'm wondering how I could retrieve this info on server side, so I can create an object with this new info.
Thanks for your help.

Well I just read his from fileupload.js:
_initXHRData: function (options) {
...
formData.append(
($.type(options.paramName) === 'array' &&
options.paramName[index]) || paramName,
file,
file.uploadName || file.name
);
...
}
(file containing webKitRelativePath)
So I guess the info is already pass to the server, don't you think? Since i'm using Servlet 3.0, I should be able to retrieve it from Part object, finger crossed...

Related

Method to clear pre-filled data of a ST.future.Component

Is there a way to clear an input field while using the ST.component("locator"); API?
Using ST.component("locator").setValue(""); results in the following error:
TypeError: ST.component(...).setValue is not a function...
PS: Is the old forum now permanently closed? Is there a way to view older questions?
Edit: Seems like the other forum was down yesterday, therefore the PS.
If it's an Ext JS field you will need to use the ST.field API in Sencha Test, which has a setValue method. This method isn't available on the more generic ST.component API.
ST.field('myfield')
.setValue('');
Or if it's a normal input field (not an Ext JS component), then you can do the following:
ST.element('#myfield')
.execute(function(field) {
field.dom.value = '';
});

Sending an excel to frontend - Angular 2, Java

I have a Java API endpoint that returns an excel (I am using content-disposition=Content-Disposition","attachment; filename=Audit.Report.xlsx).
I have another Angular-Node JS application that needs to consume this API and when the user clicks on a link, it should pull the excel and display a pop-up asking them the location to save the document. I am at a loss as to how I can do this. I tried doing the following on the server side though,
Server Code:
getAuditReport = function ( req, resp ) {
var numberOfMonths = req.query.numberOfMonths;
console.log('In first method ' + numberOfMonths);
var auditReportPromise = this.getAuditReportXlPromise ( numberOfMonths );
auditReportPromise.then ( function ( data ) {
resp.headers('Content-Disposition: attachment; filename="audit.report_'+ new Date() + '".xls"');
resp.ContentType = "application/vnd.ms-excel";
resp.status ( 200 ).send ( data );
} ).catch ( function ( err ) {
resp.status ( 500 ).send ( err );
} );
}
The getAuditReportXlPromise method returns a promise to invoke the get method of the Java API. On invoking this API via a browser, I get the excel content on the browser rather than a prompt requesting me to save the document somewhere.
Can someone suggest what's wrong here, and what I need to do on the client side for the click functionality to work.
Update 1:
Following is the code from the HTML
<a id='10051' href="{{url}}" target=_blank class="ok-white-text">
Download Report
</a>
Based on the duration the user selects, I'm building the URL - this is getting built correctly.
If your API provides the file using GET then you should be able to download the file in a simple way by just setting a link to that API (i.e. an anchor containing the link like Download).
In this scenario the browser will take over the download process (i.e. locating the folder to download to, if configured to do so).
If you want to process the file on client side, then you need to transfer it in a binary mode as suggested by multiple answer for this question.
To answer how I did manage to get around this,
Client Side:
In the component, I did the following - wrote a method on clicking the button that contains a window.open to the url - something like,
window.open("<path to the java api>", '_blank');
The link like I mentioned above was a java api that was already generating the excel file.

Unable to open local file using cordova inappbrowser on windows 8.1 platform

I am developing a phone gap application and we've recently added support for the windows 8.1 platform. The application downloads/creates files which are saved to the device using the Cordova FileSystem API.
I have successfully saved a file to the device using a URL which looks like this
ms-appdata:///local/file.png
I have checked on my PC and the file is viewable inside the LocalState folder under the app's root folder. However, when I try to open this file using inAppBrowser nothing happens; no error message is being reported and none of the inAppBrowser default events fire.
function empty() { alert('here'); } //never fires
var absoluteUrl = "ms-appdata:///local/file.png";
cordova.InAppBrowser.open(absoluteURL, "_blank", "location=no", { loadstart: empty, loadstop: empty, loaderror: empty });
I have verified that the url is valid by calling the following built-in javascript on the url
Windows.Storage.StorageFile.getFileFromApplicationUriAsync(uri).done(function (file) {
debugger; //the file object contains the correct path to the file; C:\...etc.
});
Also, adding the url as the src for an img tag works as expected.
I have also tried attaching the inAppBrowser handlers using addEventListener("loadstart") etc. but none of them are firing either. However, when I try to open "http://www.google.com" the events do fire and the inAppBrowser pops up on the screen.
After inspecting the dom I can see that the inAppBrowser element has been added, but it doesn't appear to have a source attribute set
<div class="inAppBrowserWrap">
<x-ms-webview style="border-width: 0px; width: 100%; height: 100%;"></x-ms-webview>
</div>
I have looked at other questions such as this one but to no avail. I have verified that
a) InAppBrowser is installed
b) deviceReady has fired
I have also tried changing the target to "_self" (same issue) and "_system" (popup saying you need a new app to open a file of type msappdata://) and I'm running out of ideas. Has anybody come across similar issues?
I had a similar problem. My cordova app downloads a file and then opens it with native browser (so that images, PDF files and so on are properly handled).
In the end I had to modify InAppBrowserProxy.js class (part of InAppBrowser plugin for Windows platform).
This is the code that opens the file (plain JavaScript):
// This value comes from somewhere, I write it here as an example
var path = 'ms-appdata:///local//myfile.jpg';
// Open file in InAppBrowser
window.open(path, '_system', 'location=no');
Then, I updated InAppBrowserProxy.js file (under platforms\windows\www\plugins\cordova-plugin-inappbrowser\src\windows). I replaced this code fragment:
if (target === "_system") {
url = new Windows.Foundation.Uri(strUrl);
Windows.System.Launcher.launchUriAsync(url);
}
By this:
if (target === "_system") {
if (strUrl.indexOf('ms-appdata:///local//') == 0) {
var fileName = decodeURI(strUrl.substr(String(strUrl).lastIndexOf("/") + 1));
var localFolder = Windows.Storage.ApplicationData.current.localFolder;
localFolder.getFileAsync(fileName).then(function (file) {
Windows.System.Launcher.launchFileAsync(file);
}, function (error) {
console.log("Error getting file '" + fileName + "': " + error);
});
} else {
url = new Windows.Foundation.Uri(strUrl);
Windows.System.Launcher.launchUriAsync(url);
}
}
This is a very ad-hoc hack, but it did the trick for me, and it could be improved, extended, and even standarized.
Anyway, there may be other ways to achieve this, it's just that this worked for me...
After more searching, it seems that the x-ms-webview, which is the underlying component used by PhoneGap for Windows only supports loading HTML content. This Microsoft blog post on the web view control states that
UnviewableContentIdentified – Is fired when a user navigates to
content other than a webpage. The WebView control is only capable of
displaying HTML content. It doesn’t support displaying standalone
images, downloading files, viewing Office documents, etc. This event
is fired so the app can decide how to handle the situation.
This article suggests looking at the Windows.Data.Pdf namespace for providing in-app support for reading PDFs.

How to get attached file by URL from local CouchBase-Lite?

We are trying to get an image file that has been attached to a Doc in a local CouchBase-Lite.
I'd like to be able to get this files by using the same URL syntax used for the CouchDB Remote server. (Just point to local server instead of remote)(http://wiki.apache.org/couchdb/HTTP_Document_API#Attachments)
I can seem to find how to do this.
Anyone know how? Thanks
Assuming that you are actually asking about Couchbase-Lite (aka TouchDB, ie. the embedded iOS/Android SDK) then you should look here http://couchbase.github.io/couchbase-lite-ios/docs/html/interfaceCBLAttachment.html (or the Android equivalent if that's what you're working on).
I'm not sure why you're also asking about URL syntax if that's what you're doing, so I'm not sure that is what you're doing, but hey - there's your answer. You can clarify if you were talking about something else.
This is not really an answer because I'm also looking for a solution to this. I am using CBL iOS and i want to get the local database URL to be able to get info from it.
This is what i have so far :
string[] paths = NSSearchPath.GetDirectories(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User);
var request = new NSMutableUrlRequest();
request.Url = new NSUrl(paths[0], false);
request.HttpMethod = "GET";
var data = NSUrlConnection.SendSynchronousRequest(request, out response, out error);
if(error != null)
{
Console.WriteLine("Error in SendRequest=" + error.LocalizedDescription);
throw new HttpRequestException(error);
}
And this prints out in the console : Error in SendRequest=The requested URL was not found on this server.
the URL is something like this :
file:///Users/ME/Library/Application%20Support/iPhone%20Simulator/7.0/Applications/ABFDF-ADBAFB-SFGNAFAF/Documents/users/user

Updating multimedia component using TOM.NET

I am trying to update the metadata on the multimedia image in C# using Tridion's TOM.NET API like this
componentMM.LoadXML(localComponent.GetXML(XMLReadFilter.XMLReadALL));
// make changes to the component mm multimedia text;
localComponent.UpdateXML(componentMM.InnerXML);
localComponent.Save(True)
While this works for other components, it is failing for Multimedia images.
<?xml version="1.0"?>
<tcm:Error xmlns:tcm="http://www.tridion.com/ContentManager/5.0"
ErrorCode="80040345" Category="19" Source="Kernel" Severity="2">
<tcm:Line ErrorCode="80040345" Cause="false" MessageID="16137"><![CDATA[
Unable to save Component (tcm:33-32599).
]]><tcm:Token>RESID_4574</tcm:Token>
<tcm:Token>RESID_4418</tcm:Token>
<tcm:Token>tcm:33-32599</tcm:Token>
</tcm:Line>
<tcm:Line ErrorCode="80040345" Cause="true" MessageID="15747"><![CDATA[
Unexpected element: MultimediaFileSize
]]><tcm:Token>MultimediaFileSize</tcm:Token>
</tcm:Line>
<tcm:Details>
<tcm:CallStack>
<tcm:Location>ComponentBL.CheckMultiMediaProperties</tcm:Location>
<tcm:Location>ComponentBL.CheckMultiMediaProperties</tcm:Location>
<tcm:Location>ComponentBL.Update</tcm:Location>
<tcm:Location>XMLState.Save</tcm:Location>
<tcm:Location>Component.Save</tcm:Location>
</tcm:CallStack>
</tcm:Details>
</tcm:Error>
Can you please let me know what am I doing wrong here?
Thanks for your responses. I was deleting the node but at the wrong place. I update the code like this and it works fine now.
if (localComponent.IsMultimediaComponent)
{
XmlNode multimediaFileSizeNode = localComponentXML.SelectSingleNode("//*[local-name()='MultimediaFileSize']",tridionNamespace);
XmlNode dataNode = multimediaFileSizeNode.ParentNode;
dataNode.RemoveChild(multimediaFileSizeNode);
}
localComponent.UpdateXML(localComponentXML.InnerXml);
Include only the tcm:Metadata node in your update?
Specifically, it is complaining about you specifying the size of the mm file, which you shouldn't, that's a system property. Clean up the XML you receive from Tridion to remove that property (it might then complain about another property, just do what it asks you to).
EDIT: Reading the error messages is a great skill to have...
When you do this you need to only save the modified metadata data (not the entire XML). Try removing all of the child nodes except tcm:Metadata from the XML structure before calling .UpdateXML()
Perhaps you could paste your sample XML if you need further assistance.
I usually do this way:-
mComponent = (Component)mTDSE.GetObject("YOUR-COMPONENT-ID", EnumOpenMode.OpenModeView, null, XMLReadFilter.XMLReadAll);
mComponent.CheckOut(false);
mComponent.MetadataFields["YOUR-METADATA-FIELD-NAME"].value[1] = "VALUE TO BE REPLACED";
mComponent.Save(true);

Resources