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
Related
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...
I am currently trying to convert a smallish app from nodejs to golang (hence the two tags) but I'm running into a bit of trouble in doing so.
Essentially it is a very simple http POST login which I can't seem to realise. The background is that my university provides a calendar export function and I would like to provide this calendar as a feed that could be added to Google Cal.
Now the thing is that I have the whole thing working in node, but I would really like to be able realise it in go aswell.
The important bit of node code would be
var query = url.parse(req.url, true).query;
var data = {
u: query.user, // Username
p: query.password, // Password
};
needle.post(LOGIN_URL, data, {}, function (error, response) {
//extract cookies etc.
});
which is working like a charm but if I try to do the same in go
import "github.com/parnurzeal/gorequest"
//...
resp, body, err := gorequest.New().Post(LOGIN_URL).Send("u=user&p=pass").End()
//extract cookies etc.
I end up an invalid (timed out) session. I already tried using just net/http in go, which doesn't seem to change anything.
The result the POST request yields is a 302 redirect to an overview page (Btw: it is ASP based). Could it be that this is what's causing the problem, since gorequest then fetches that overview page without the cookies returned in resp, effectively creating a new session that isn't authorized, or am I overlooking something terribly simple?
So it seems that I found the answer myself by following your advice and using "net/http" and digging a little deeper into what the http.Client actually does. To anyone who might encounter similar problems, here is my solution:
http.Client automatically redirects if it receives a 30x response by the server see documentation. Although one can override the redirect policy, I was unable to prevent redirection entirely.
Additionally it seems as if the client has a bug (what I would call it at least), as it drops all header upon redirect see the issue or in the source where new headers are created.
While searching around in net/http I found http.DefaultTransport which is used by http.Client and does not redirect. It seems somewhat lower level and exactly what I was after. The following piece of code demonstrates how I replaced the line realised with gorequest from above:
data := url.Values{"u": {USER}, "p": {PASS}}
req, err := http.NewRequest("POST", LOGIN_URL, bytes.NewBufferString(data.Encode()))
//I needed quite some time to figure out that I needed to set the content type accordingly
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
//...
resp, err := http.DefaultTransport.RoundTrip(req)
//...
//resp.Header["Set-Cookie"] now contains the login/session cookies
Although I need to extract cookies myself and set a few header values, the solution works perfectly and I am quite happy with it. If anybody has some improvements to my solution or any other advice I am glad to hear it. And thanks to JimB and Volker :).
I'd want to use a login page to access different firewalls, so I need to get information about the firewall I'm logging in.
In my controller I'd use
$this->container->get('security.context')->getToken()->getProviderKey()
but as an anonymous user I don't have access to getProviderKey method.
I could also parse
_security.xxx.target_path
to get xxx firewall but I'm looking for a more general solution if it exists at all.
Any idea?
As of symfony 3.2, you can now get the current firewall configuration using the following:
public function indexAction(Request $request)
{
$firewall = $this->container
->get('security.firewall.map')
->getFirewallConfig($request)
->getName();
}
Ref: http://symfony.com/blog/new-in-symfony-3-2-firewall-config-class-and-profiler
For Symfony 3.4 I wrote this to avoid referencing the non-public "security.firewall.map" service:
$firewallName = null;
if (($firewallContext = trim($request->attributes->get("_firewall_context", null))) && (false !== ($firewallContextNameSplit = strrpos($firewallContext, ".")))) {
$firewallName = substr($firewallContext, $firewallContextNameSplit + 1);
}
(Referencing "security.firewall.map" on 3.4 will throw an exception.)
Edit: This will not work in a custom exception controller function.
I was doing a little research on this myself recently so that I could send this information in an XACML request as part of the environment.
As far as I can tell from GitHub issues like this one:
https://github.com/symfony/symfony/issues/14435
There is currently no way to reliably get the information out of Symfony except the dirty compiler pass hack suggested on the linked issue. It does appear from the conversation on these issues, they are working on making this available, however, the status is still open, so we will have to be patient and wait for it to be provided.
#Adambean's answer is pretty elegant, but I'd write it as a one-liner:
$firewallName = array_slice(explode('.', trim($request->attributes->get('_firewall_context'))), -1)[0];
The difference is that $firewallName will always be a string (which may be empty).
Also, please note that this answer (like #Adambean's) doesn't work for a firewall with a dot in its name.
Hi
I have a flash image gallery that worked just fine, until few days a go it stopped loading the images. the debugger throws this error :
SecurityError: Error #2000: No active security context.
can someone explain what can be the cause?
I've run into this problem when working with loading images where the path is located in an external XML file. So... I load the XML get the path from it but then the problem I had was I was loading 30+ images and the error was popping up only 6 times so.. I had no idea which file locations where the bad ones.
If you want flash to out put more info than just :
SecurityError: Error #2000: No active security context.
Add this event listener to your Loader:
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
and finally this function:
protected function ioErrorHandler(e:IOErrorEvent):void{
trace(e.text);
}
With this in place your Security Error will convert to a URL Not Found Error with the file location you supplied. With this information in hand it should be easier for you to debug the problem.
Error #2035: URL Not Found. URL: file:////Volumes/Macintosh%20HD/Users/cleanshooter/Documents/Website%20/here/there/everywhere/30805/filename.jpg
I faced this issue before,the final conclusion was related to incorrect image path or name
Did your images extensions change, possibly from like .jpg to .JPG or something?
Typically this is called if there is a problem with your external media. Here's a workaround for it, but I typically try and solve versus make it go away.
setTimeout( function():void{fileReference.load();}, 1);
Hope this helps.
I ran across this issue and used the above setTimeout example but for a slightly different purpose. I was calling a php script that hit Twitter and got the same security issue in Flash debug player. I just wanted to add my example which builds on the above to show how you can use this "workaround" for URLLoader as well as fileReference.
var myXMLLoader:URLLoader = new URLLoader();
var urlStr:String = "http://www.yourdomain.com/php/twitter.php";
var myVariables:URLVariables = new URLVariables();
myVariables.twitterID = "yourtwitterID";
var myURLRequest:URLRequest = new URLRequest(urlStr)
myURLRequest.data = myVariables;
setTimeout(function():void { myXMLLoader.load( myURLRequest ); }, 1);
myXMLLoader.addEventListener(Event.COMPLETE, onXMLLoadHandler);
You need to handle the error:
loader.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, onHTTPError);
protected function onHTTPError(e:HTTPStatusEvent):void{
trace("HTTPError"+e.status);
}
This way it will handle the error and works fine.
In response to headwinds:
In AS3 you need to import flash.utils.setTimeout. The syntax for setTimeout is setTimeout(A, B, ...rest);
Where B is the function to get called afterwards,
A is the delay in ms (e.g. 1000 for a second)
and C is any number of parameters you need to provide for the function, separated by a comma.
E.g.
import flash.utils.setTimeout;
// package, etc
//main function
setTimeout(respond, 500, true, false);
private function respond(A : Boolean, B : Boolean) : void {
var result : Boolean = A == B;
trace(result);
}
I have some client side code that uploads an Outlook email to a document library and as long as the path is pointing to the root of the doc library it works just fine.
#"https://<server>/sites/<subweb>/<customer>/<teamweb>/<Documents>/" + docname;
is the projectUrl in this function :
public bool SaveMail(string filepath, string projectUrl)
{
try
{
using (WebClient webclient = new WebClient())
{
webclient.UseDefaultCredentials = true;
webclient.UploadFile(projectUrl, "PUT", filepath);
}
}
catch(Exception ex)
{
//TO DO Write the exception to the log file
return false;
}
return true;
}
but I have not been able to figur out how to upload to an existing folder i.e. "Emails" in the same document library.
Not even Google seems to know the answer :-)
Note: I know that I could use something like the Copy web service within SharePoint to move the file to its final destination, but that is more like a workaround.
When will I learn not to work that late into the night :-(
Sorry about that question. Igalse is right, I just needed to add "emails/" to the URL. I could swear that I had tried that, but then again it sure looks like I didn't.
With your code I just added /Emails/ to the projectUrl and the upload worked just fine. Have you tried that? Maybe you have permission problem.