ASINetworkQueue without setting DownloadDestinationPath - asihttprequest

I want to fetch multiple images from the server for which I wish to use the ASINetworkQueue. I was wondering if setting the downloadDestinationPath using setDownloadDestinationPath:path for ASIHTTPRequest object is necessary. Is there a way to use ASINetworkQueue without setting the DownloadDestinationPath? If so, how to go about it? Also what happens to the images once they are downloaded in the Documents directory. I do not wish to pile up all the images as my project involves extensive use of images.

I used the tag property of the ASIHTTPRequest object to set different tags for each of my request before adding them to the ASINetworkQueue object.
ASIHTTPRequest *request;
request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:[imageURLDictionary objectForKey:#"test1"]]];
request.tag=1;
[networkQueue addOperation:request];
request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:[imageURLDictionary objectForKey:#"test2"]]];
request.tag=2;
[networkQueue addOperation:request];
request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:[imageURLDictionary objectForKey:#"test3"]]];
request.tag=3;
[networkQueue addOperation:request];
[networkQueue go];
And on success and failure handled them in the delegate method.
- (void)imageFetchComplete:(ASIHTTPRequest *)request
{
if (request.tag==1) {
_image1.image=[UIImage imageWithData:request.responseData];
}
if (request.tag==2) {
_image2.image=[UIImage imageWithData:request.responseData];
}
if (request.tag==3) {
_image3.image=[UIImage imageWithData:request.responseData];
}
}

Related

how to read additional parameters in alfresco 5.1.1- aikau faceted search

Custom Search UI will be populated when user selects Complex asset in the Advance search screen drop down(apart from Folders,Contents) where 12 fields will be displayed .So when user clicks search button ,need to read those values and redirect to the alfresco repo files(org/alfresco/slingshot/search/search.get.js).We have already customized these files(search.get.js,search.lib.js) existed in the repository to suit out logic and working fine in 4.2.2;As we are migrating to 511,so we need to change this logic in customized faceted-search.get.js to read these values.How to write this logic in customized facted-search.get.js?
It's not actually possible to read those URL hash attributes in the faceted-search.get.js file because the JavaScript controller of the WebScript does not have access to that part of the URL (it only has information about the URL and the request parameters, not the hash parameters).
The hash parameters are actually handled on the client-side by the AlfSearchList widget.
Maybe you could explain what you're trying to achieve so that I can suggest an alternative - i.e. the end goal for the user, not the specifics of the coding you're trying to achieve.
We will be reading the querystring values something like below in the .get.js file.
function getNodeRef(){
var queryString = page.url.getQueryString();
var nodeRef = "NOT FOUND";
var stringArray = queryString.split("&");
for (var t = 0; t < stringArray.length; t++) {
if (stringArray[t].indexOf('nodeRef=') > -1) {
nodeRef = stringArray[t].split('=')[1];
break;
}
}
if (nodeRef !== "NOT FOUND") {
nodeRef = nodeRef.replace("://", "/");
return nodeRef;
}
else {
throw new Error("Node Reference is not found.");
}
}
It may be help you and we will wait for Dave Drapper suggestion also.

Create Native Client MediaStreamVideoTrack and send to javascript

According to the docs for the Native Client MediaStreamVideoTrack there is a constructor that "Constructs a MediaStreamVideoTrack that outputs given frames to a new video track, which will be consumed by Javascript."
My idéa was then to put frames into this video track, that can later be displayed by javascript in a video tag or passed to a RTCPeerConnection.
I don't know if do it correctly, but from the docs for PostMessage states that it should be supported to pass a resource. But with the simple Native Client code below I only get a warning in the browser console: "Failed to convert a PostMessage argument from a PP_Var to a Javascript value. It may have cycles or be of an unsupported type."
virtual void HandleMessage(const pp::Var& var_message) {
if (!var_message.is_dictionary()) {
LogToConsole(PP_LOGLEVEL_ERROR, pp::Var("Invalid message!"));
return;
}
pp::VarDictionary var_dictionary_message(var_message);
std::string command = var_dictionary_message.Get("command").AsString();
if (command == "create_track") {
pp::MediaStreamVideoTrack video_track = pp::MediaStreamVideoTrack::MediaStreamVideoTrack(this);
pp::VarDictionary dictionary;
dictionary.Set(pp::Var("track"), pp::Var(video_track));
PostMessage(dictionary);
}
}
Am I doing something wrong, or something that isn't just supported? :)
A MediaStreamVideoTrack can only be created by the page (not the plugin) and passed to the plugin by PostMessage. See this example code:
https://code.google.com/p/chromium/codesearch#chromium/src/ppapi/examples/media_stream_video/media_stream_video.cc
https://code.google.com/p/chromium/codesearch#chromium/src/ppapi/examples/media_stream_video/media_stream_video.html

How do i check whether the url is responsive or not

I have Image Url in my Database and i want to check whether the URL is responsive or not in the browser .
please Help me .
For Example :
http://images.jactravel.co.uk/6008_1_1.jpg
or
http://images.jactravel.co.uk/6049_2_4.jpg
now how can i check automatically this url is responsive or not
I assume that by responsive you mean whether you can get a response when you call a specific URL or not.
To do that without actually downloading the content, you can use the HttpClient.GetAsync(string,HttpCompletionOption) with an HttpCompletionOption of ResponseHeadersRead. This will make GetAsync return immediately with a status code (eg 200, 404 or 500) without waiting to download the entire content, eg:
using (var client = new HttpClient())
{
using(var response = await client.GetAsync("http://mysite/myimage.jpg",
HttpCompletionOption.ResponseHeadersRead))
{
if (response.IsSuccessStatusCode)
{
//The URL is good
}
}
}
To actually read the content, you need to access one of the Read methods of the response's Content property. For example, you can use the CopyToAsync to copy the content to a file stream, or use ReadAsByteArrayAsync to read the content as a byte array, eg:
var buffer=await response.Content.ReadAsByteArrayAsync();

Spoofing HTTP Referrer data using ASP.NET

Answers on here and various other sites are often full of warnings not to trust HTTP Referrer headers because they are 'so easily' spoofed or faked.
Before I go any further - no, I'm not up to no good - but I do want to run some referrer-dependant tests.
Whilst I don't doubt that the warnings about fake referrers are true, I can't really find much detailed info on how they can be manipulated. Even the Wikipedia article only talks about it in general terms.
I'm about to play with the RefControl addin for FireFox.
Programatically (in ASP.NET specifically) the UrlReferrer is a read-only property, so I don't see how I can fire off requests with fake referrer data if I can't set it? Do I really have to do it manually?
How would I use ASP.NET to send a request to my site with a user-supplied variable to populate the referrer header?
EDIT : As per my comment below, I ideally want to take an incoming request, manupulate the referrer data and then pass the request on to another page, intact. If I can make it appear intact by building a new one from scratch and copying the original properties, then that is fine too.
I don't know if this exactly what you want, but in general, you should be able to spoof the value of the UrlReferer property (even if it's read-only) in HttpContext.Current.Request by using a bit of reflection.
For example:
FieldInfo fi = HttpContext.Current.Request.GetType().GetField("_referrer", BindingFlags.NonPublic | BindingFlags.Instance);
string initialReferer = HttpContext.Current.Request.UrlReferrer.ToString();
if (fi != null)
fi.SetValue(HttpContext.Current.Request, new Uri("http://example.com"));
string fakedReferer = HttpContext.Current.Request.UrlReferrer.ToString();
On VS; these are the values before and after changing the UrlReferrer:
initialReferer
"http://localhost/Test/Default.aspx"
fakedReferer
"http://example.com/"
If you open the System.Web assembly using ILSpy you'll notice that the UrlReferrer property looks something like this:
public Uri UrlReferrer
{
get
{
if (this._referrer == null && this._wr != null)
{
string knownRequestHeader = this._wr.GetKnownRequestHeader(36);
if (!string.IsNullOrEmpty(knownRequestHeader))
{
try
{
if (knownRequestHeader.IndexOf("://", StringComparison.Ordinal) >= 0)
{
this._referrer = new Uri(knownRequestHeader);
}
else
{
this._referrer = new Uri(this.Url, knownRequestHeader);
}
}
catch (HttpException)
{
this._referrer = null;
}
}
}
return this._referrer;
}
}
This likely isn't going to get you what you want. But you can edit the Referror of an HttpWebRequest. I don't think there is a way of editing the referrer of your request in context.
using System.Net;
HttpWebRequest Req= (HttpWebRequest)System.Net.HttpWebRequest.Create("http://somewhere.com/");
Req.Referer = "http://www.fakesite.com";

FileReference.load() does not as excepted

I used Flash player 10, and Flex SDK 3.4. The code as followings:
// Following comes callbacks
function imageLoadOpenCallback(evt:Event):void
{
trace("in--open");
}
function imageLoadCompleteCallback(evt:Event):void
{
trace("in--load");
var fr:FileReference = evt.target as FileReference;
trace(fr.data);
}
function imageLoadErrorCallback(evt:IOErrorEvent):void
{
trace("in--ioerror");
}
function imageSelectCancelCallback(evt:Event):void
{
trace("in cancel");
}
function imageSelectCallback(evt:Event):void
{
trace("in -- select");
for (var i:int=0; i<frl.fileList.length; i++)
{
frl.fileList[i].addEventListener(Event.OPEN, imageLoadOpenCallback);
frl.fileList[i].addEventListener(Event.COMPLETE, imageLoadCompleteCallback);
frl.fileList[i].addEventListener(IOErrorEvent.IO_ERROR, imageLoadErrorCallback);
frl.fileList[i].load();
trace(frl.fileList[i]);
trace(frl.fileList[i].creationDate);
trace(frl.fileList[i].creator);
trace(frl.fileList[i].data);
trace(frl.fileList[i].name);
}
}
// Following comes UI handlers
function onAddPictures():void
{
var imageFilter:FileFilter = new FileFilter("Images", "*.jpg;*.png");
frl.addEventListener(Event.SELECT, imageSelectCallback);
frl.addEventListener(Event.CANCEL, imageSelectCancelCallback);
frl.browse([imageFilter]);
}
Only the imageSelectCancelCallback handler get called when I select some files in the dialog. But no load/open/io_error handler get called at all. I have Google some code example, in which it used FileReference instead of FileReferenceList. I don't know the reason, could you please help me?
In Air the fileReference objects in fileReferenceList do not fire the complete event when doing fileList[i].load(). In a Flex project it works fine. Adobe has not responded to bug reports on this appropriately.
Make sure in your compiler settings for flex, that you have at least 10.0.0 for "Use a specific version".
The main reason to use FileReferenceList instead of FileReference would be if you need to upload multiple files at once. If you only want to allow uploading one file at once, simply use FileReference.
Some clarification: imageSelectCallback(), and NOT imageSelectCancelCallback(), should get called when you select some files in the file browser AND click OK. imageSelectCancelCallback() is only called when you click Cancel.
Other than that, I never used the load() API, but I did use the upload(URLRequest) API. I am not sure what's your use case, but if you need to upload an image to a server, you should use the upload() method.
Speaking of upload events, I experienced some reliability issues when listening to Event.COMPLETE events, so I actually got better results listening to DataEvent.UPLOAD_COMPLETE_DATA.

Resources