I receive url path from a meteor server and trying to display it. but onError logs
Error decoding image data <NSData 0x7f9d820c5a00; 1196 bytes>
I log the path and view it on browser and its there. what's causing it? or at least what does this error mean?
Edit:
I'm using meteorjs for server. I think its has something to do with it. I use static images online and it works just fine.
PS: I dont code in objective C
I think, you are directly displaying NSData without converting in to image. Do like this:
NSData *data = [NSData datawithContentsOfURL:URLString];
UIImage *image = [UIImage imageWithData:data];
Related
I am working on this problem and the proposed solution works for me.
However, now I need to make this work in my actual application which is an AWS Beanstalk .NET web application. My beanstalk application knows the url source of the picture. Knowing the url, I can get a stream and process the file (by creating a byte array and even a Bitmap object).
However, it seems that to get the file properties as mentioned above (such as the camera type or painting application that created the file), I really need a local file because that is the expected input argument.
This is a problem for me. I know the http link, I know the bytes but I have no such thing as a file path.
How can I solve this? I need the windows file properties.
If I understood you correctly, you want to read image metadata from a URL without saving it to a file first, i.e. directly from the Internet.
Here is one way that works for me:
string demoImageUrl = "https://raw.githubusercontent.com/ianare/exif-samples/master/jpg/Canon_40D.jpg";
byte[] imgData = null;
using (var wc = new WebClient())
{
imgData = wc.DownloadData(demoImageUrl);
}
using (var sr = new MemoryStream(imgData, false))
{
BitmapSource image = BitmapFrame.Create(sr);
BitmapMetadata md = (BitmapMetadata)image.Metadata;
string comment = md.Comment;
string title = md.Title;
string dateTaken = md.DateTaken;
}
You need to add references to PresentationCore and WindowsBase assemblies and also include the following namespace:
using System.Windows.Media.Imaging;
I have the following part of code:
let client = new WebClient()
let url = "https://..."
client.DownloadFile(Url, filename)
client.Dispose()
In which code i am performing a HttpGet method in which method i get a file excel with some data.
The method is executed correctly because i get my excel file.
The problem is that the content of my file excel is like this:
I think its because i don't pass ContentType:"application/vnd.ms-excel"
So anyone can help how can I pass that ContentType in my Client in F# ?
If you want to add HTTP headers to a request made using WebClient, use the Headers property:
let client = new WebClient()
let url = "https://..."
client.Headers.Add(HttpRequestHeader.Accept, "application/vnd.ms-excel")
client.DownloadFile(Url, filename)
In your case, I think you need the Accept header (Content-Type is what the response should contain to tell you what you got).
That said, I'm not sure if this is the problem you are actually having - as noted in the comments, your screenshot shows a different file, so it is hard to tell what's wrong with the file you get from the download (maybe it's just somewhere else? or maybe the encoding is wrong?)
I'm using an XPS file reader to produce HTML output via the GroupDocs Viewer, and it's giving a result in HTML format using the UseHtmlBasedEngine property but giving me error in top corner of viewer like HTTP Error 404.0 not found.
string fileName = (sender as LinkButton).CommandArgument;
string scriptLibraries = Viewer.CreateScriptLoadBlock().LoadJquery().LoadJqueryUi().ToString();
string inlineDocPreviewScript = Viewer.ClientCode()
.TargetElementSelector("#divShow")
.FilePath(fileName)
.EnableRightClickMenu(true)
.ShowThumbnails(true)
.OpenThumbnails(true)
.ZoomToFitWidth()
.Quality(100)
.MinimumImageWidth(ImageWidth)
.UseHtmlBasedEngine(true,true,true,true)
.ToString();
HeadControl.Controls.Add(new Literal() { Text = scriptLibraries });
BodyControl.Controls.Add(new Literal() { Text = inlineDocPreviewScript });
How to resolve HTTP 404.0 not found error in this scenario?
Looks like you have changed the root URL of the application or have generated document’s cache with a URL and then changed it or deployed the application to another server. To resolve the issue, simply delete the Viewer cache – the "temp" folder, which can be found in the root storage path (which you’ve set in the .SetRootStoragePath() method).
If this will not help you, please share with us the following details: which type of the project you use (We3b Forms or MVC) and a code example of the Viewer initialization and web.configs.
As for the reading html and image files from different folders - please provide more info about the use case because it's not very clear what you actually want to do. Please post your request on our support forum at: http://groupdocs.com/Community/Forums/Default.aspx
I want to upload an image from IOS device to Google datastore.
This is how I did it:
On client side, I use cocos2d to get image raw data. image->getData(), which returns an (unsigned char*) type. I guess it's in base64.
I set, std::string postdata = "image=" + (char *)(image->getData());.
I use cocos2d HttpClient to send the postdata to a servlet.
On the servlet, I use request.getParameter("image"); to get the image data. But I got an java.lang.IllegalArgumentException: !utf8 ERROR!
However, if I just set postdata = "image=XXXX", the servlet is able to return me "XXXX", which is what I want. So I guess the problem is:
"image=" is in UTF8, but image data is in base64.
Then servlet does not know how to decode the string and returns me !UTF8 error.
I don't know if my understanding is correct?
All I want is to let servlet receive image data and send it back to client.
Is any one know how to do it?
Thanks in advance.
Regards
I solved the problem. It's just I need to encode the image data to base64, then post it to the servlet. Thanks any way.
I have written downloading a file in a simple manner:
#ResourceMapping(value = "content")
public void download(ResourceRequest request, ResourceResponse response) {
//...
SerializableInputStream serializableInputStream = someService.getSerializableInputStream(id_of_some_file);
response.addProperty(HttpHeaders.CACHE_CONTROL, "max-age=3600, must-revalidate");
response.setContentType(contentType);
response.addProperty(HttpHeaders.CONTENT_TYPE, contentType);
response.addProperty(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename*=UTF-8''"
+ URLEncoder.encode(fileName, "UTF-8"));
OutputStream outputStream = response.getPortletOutputStream();
byte[] parcel = new byte[4096];
while (serializableInputStream.read(parcel) > 0)
outputStream.write(parcel);
outputStream.flush();
serializableInputStream.close();
outputStream.close();
//...
}
The SerializableInputStream is described here - JavaDocs. It allows an InputStream to be serialized and, for instance, passed over remoting.
I read from input and write it to the output, not all bytes at once. But unfortunately the portlet isn't "streaming" the contents - the file (e.g. an image) is sent to the browser only after reading the entire input stream - this is how it looks like. I see the file being read from the database (from live logs), but I don't see any "growing" image on the screen.
What am I doing wrong? Is it possible to really stream a file in Liferay 6.0.6 and Spring Portlet MVC?
Where are you doing this? I fear that you're doing this instead of rendering your portlet's HTML (e.g. render phase). Typically the portlet content is embedded in an HTML page, thus you need the resource phase, which (roughly) behaves like a servlet.
Also, the code you give does not match the actual question you ask: You use a comment //read from input stream (file), write file to os and ask what to do differently in order to not have the full content in memory.
As the comment does not have anything in memory and you could loop through reading from the input file while writing to the output stream: What's the underlying question? Do you have problems with implementing download-streaming in a portal environment or difficulties (i.e. using too much memory) reading from a file while writing to a stream?
Edit: Thanks for clarifying. Have you tried to flush the stream earlier? You can do that whenever you want - e.g. every loop (though that might be a bit too much). Also, keep in mind that the browser as well as the file itself must handle it in a way that you expect: If an image is not encoded "incrementally" a browser might not show it that way.
Have you tried this with huge files as well? It might be that the automatic flushing is just not triggered because your files are too small for it to be triggered...
Also, I think that filename*=UTF-8'' looks strange. Might be valid encoding, but I've never seen this