I am try to convert inputstream to Image
I have tried using the below code.
var img = Image.FromStream(imagePathErrorMessage.StreamObject);
I need to pass the img to mvc view
#foreach (var img in imageSet)
{
<div class="thumbnail thumbnail-inline">
<label class="checkbox-inline">
<input type="checkbox" onchange="DisplayedImageOnchange(this)" value="#img.Id" />
<img src="#img.Url" class="img-thumbnail" />
</label>
<div class="btn-block">
<input type="file" class="replace file-loading" />
<button class="btn btn-xs btn-danger delete">delete</button>
</div>
</div>
}
public JsonResult Upload(object model)
{
var img = Image.FromStream(imagePathErrorMessage.StreamObject);
return Json(new AdCreative { Id = 100, Url = Url.Content("data:image;base64,#System.Convert.ToBase64String('" + img + "')") }, JsonRequestBehavior.AllowGet);
}
it throws the following error :
the above inputstream from amazon s3 response.
Firstly, you may find more information by clicking on 'View Detail' in the exception window, and expanding any InnerException properties.
Have you checked that imagePathErrorMessage.StreamObject is non-null and provides an image in one of the accepted formats?
These are JPG, BMP, TIF, GIF and PNG. If your image contains transparency data, you should convert it to a PNG first. You may not use RAW data, for that I think you'd want BitmapImage instead of Image
If the stream is valid, it will also need to be at position 0 before you start the read, for example:
imagePathErrorMessage.StreamObject.Position = 0;
var img = Image.FromStream(imagePathErrorMessage.StreamObject);
Edit for OP Edit:
Do you need to set the ResponseStream back to position zero after it is converted but before it is copied to destination?
(if at the breakpoint shown in your screenshot, you hovered over destination would it show a stream with 61153 length and CurrentPosition 0?)
Second Edit:
This answered post Loading an image from a stream without keeping the stream open describes why when using Image.FromStream then the stream needs to remain open for the lifetime of the image.
Related
Since I'm injecting a <span ui-popover></span> after the DOM is constructed I need to reinitiate the popovers otherwise it won't show.
Is there away to do that?
HTML
<div ng-repeat="i in comments">
<div id={{i._id}} class="task" commentId={{i._id}}> {{i.text}} </div>
</div>
I'm using the external rangy library that injects 's around highlighted texts. You can also inject elementAttirbutes to accommodate these span, This is shown in this part of the code:
JS
function initHighLighter() {
var cssApplier = null;
highlighter = rangy.createHighlighter(document);
cssApplier = rangy.createClassApplier('highlight-a',{elementAttributes: {'uib-popover':"test"}}/*, {elementAttributes: {'data-toggle':"popover", 'data-placement':"bottom", 'title':"A for Awesome", 'data-selector':"true", 'data-content':"And here's some amazing content. It's very engaging. Right?"}}*/);
highlighter.addClassApplier(cssApplier);
cssApplier = rangy.createClassApplier('highlight-b', {elementAttributes: {'uib-popover':"test"}}/*, {elementAttributes: {'data-toggle':"popover", 'data-placement':"bottom", 'title':"B for Best", 'data-selector':"true", 'data-content':"And here's some amazing content. It's very engaging. Right?"}}*/);
highlighter.addClassApplier(cssApplier);
}
I'm calling on to highlight parts of the texts, only after I upload them from the server (highlighter1 calls on init highlight written above)
JS
(function(angular) {
'use strict';
angular.module('myApp', ['ui.bootstrap'])
.controller('Controller', function($scope, $http, $timeout) {
$http.get('/comments')
.success(function(response) {
$scope.comments = response;
var allEl=[];
var i;
for (i=0; i<response.length; i++) {
allEl.push(response[i]._id);
}
$http.post('/ranges', {"commentIds":allEl})
.success(function(result){
result.forEach(function(item){
highlighter1(item.dataAction, item.rangyObject, true);
})
})
});
})
})(window.angular);
So in the end my DOM is being changed AFTER I initiated everything and then the attributes associated with the span don't do anything.
your markup should be (notice the prefix)
<span uib-tooltip="hello world"></span>
or if you want dynamic content
$scope.welcomeMessage = "hello world"; // inside controller
..
<span uib-tooltip="{{welcomeMessage}}"></span>
if you want to reinitialize the tooltip, you can trigger a $destroy event and have it rebuilt, one way if by using ng-if and setting it to true when you need it.
<span ng-if="doneUpdating" uib-tooltip="hello world"></span>
Dear Stackoverflow users,
I would like to know how to find out the URL of a file after it has been uploaded to a file server, so that I can view it in ex. safari.
Not possible... FileZilla has no idea how FTP paths map to HTTP paths or if there even is an HTTP path to get to whatever you uploaded
i think , this action is needed. but filezilla not supported.
but you can use this web app client.
Ftp path To http path (view demo)
html code
<h2>Ftp path To http path</h2>
<table>
<tr>
<td><label for="http_path">http base path</label></td>
<td><input id="http_path" type="text"> (e.g., http://example.com)</td>
</tr>
<tr>
<td><label for="ftp_path">ftp path</label></td>
<td><input id="ftp_path" type="text"> (e.g., ftp://username#domainOrIp/path)</td>
</tr>
<tr>
<td><label for="output">output</label></td>
<td><input id="output" type="text"></td>
</tr>
</table>
css code
#http_path,#ftp_path{
width : 200px;
}
#output{
width : 500px;
}
js code
function setCookie(cname, cvalue, exdays) {
//w3schools.com
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname) {
//w3schools.com
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
$(function(){
$('#http_path').val(getCookie('http_path'));
$('#http_path,#ftp_path').change(function(e){
setCookie('http_path',$('#http_path').val(),365);
$('#output').val(
$('#http_path').val()
+ '/' +
$('#ftp_path').val().split('/').slice(3).join('/')
);
});
$('#output').click(function(){
$(this).select();
});
});
Some other FTP client software does have this ability. The OSX client "Fetch", for example, asks you for the root http directory the first time you try to get a URL, and then remembers this. If you do this the first time in the highest level http directory, then it will also work for subdirectories.
Right click the remote file and select "Copy URL to clipboard", then paste somewhere else. Of course this is only getting you the FTP URL of the file.
So I am trying to navigate http://www.historicflyingclothing.com/shop.php by first clicking on an item in the dropdown. After posting the value from the dropdown using :
string poststring = String.Format("Cat1={0}", "7");
CookieContainer cookie = new CookieContainer();
HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create("http://www.historicflyingclothing.com/shop.php");
httpRequest.Method = WebRequestMethods.Http.Post;
httpRequest.CookieContainer = cookie;
httpRequest.AllowWriteStreamBuffering = true;
httpRequest.ProtocolVersion = HttpVersion.Version11;
httpRequest.AllowAutoRedirect = true;
httpRequest.ContentType = "application/x-www-form-urlencoded";
byte[] bytedata = Encoding.UTF8.GetBytes(poststring);
httpRequest.ContentLength = bytedata.Length;
Stream requestStream = httpRequest.GetRequestStream();
requestStream.Write(bytedata, 0, bytedata.Length);
requestStream.Close();
HttpWebResponse httpWebResponse = (HttpWebResponse)httpRequest.GetResponse();
Stream responseStream = httpWebResponse.GetResponseStream();
I was able to get the items on the page.
The problem is when I need to click on the next button. I was hoping to use the CookieContainer to help me navigate but I cant figure out what the post data should be. The html code for the next click is:
<form method="POST" class="shopform" action="shop.php">
<p style="text-align: center"> <input type="IMAGE" name="Submitnext" src="buttons/next.gif" value="npage" style="margin-bottom: -4pt"></p>
</form>
With the drop down the name was "Cat1" and value was "7" but what do I use for this IMAGE?
From the HTML you've provided and listed on that website, the values you need to post are:
Submitnext=npage
You'll noticed the name you're posting is contained in the "name" attribute and the value is contained in the "value" attribute.
I am developing an iPad application using Phonegap (Cordova-1.9.0) and jQuery Mobile 1.0.1 . I need to use image gallery for my application.In my application.I found photoswipe image gallery.
I capture image from iPad camera and save as Camera.DestinationType.DATA_URL (Phonegap api ). My imagea are saved as base64, type.
Photoswipe image gallery works fine when I save image as Camera.DestinationType.FILE_URI.
But my problem is that how do i use photoswipe gallery using Camera.DestinationType.DATA_URL?
thank you
I found a solution for a similar problem.
I use photoSwipe with base64 in a web page, and it works this way:
<li><img src="data:image/png;base64,<c:out value='${entry.imagenString}'/>"></li>
In the href and src attributes I put the string of base64 with the notation to indicate that is a base64.
I'll try to use it in Phonegap, but I think that must be the same code.
Edit: I tested it in Phonegap and it works.
I use this :
var imagesArray = data.callback.include.images;
// images :
if(imagesArray && imagesArray.length > 0 && imagesArray != null && imagesArray != undefined){
var images = imagesArray.map((item)=>{
var link = item.trim();
var base = link.split('base64,');
var a = base[0];
var b = base[1];
return `<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href=${a}base64,${b} itemprop="contentUrl" data-size="1024x1024">
<img src=${a}base64,${b} itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">CAPTION :</figcaption>
</figure>`
})
// building the gallery :
var now = new Date().getTime();
var galleryClassName = "gal-" + shareId + "-" + commentId + "-" + now;
var gallery = `<div class="comments-gallery ${galleryClassName} gallery" itemscope itemtype="http://schema.org/ImageGallery">
${images}
</div>`;
}else { gallery = "" }
then include the gallery variable and then initialize it by calling its class as
var output = `<div class="row"> ${gallery} </div>`;
// init gallerires :
initPhotoSwipeFromDOM("." + galleryClassName);
I am writing a simple "Book" create page in ASP.NET MVC. User can create book by filling title,year etc.. and selecting a cover image. When user press "Create" button Form sends image and data to Controller action called "Create" then I save image to disk and data to database.
But I want to display image when user select image by file dialog.To do this As far as I know I must upload image to server then display in client browser.But if a user cancels the "Create" operation after uploading image, the image will remain in the server's disk.So How can I deal with these temp images or Is there any way to display image in client browser without upload to server?
Due to security reasons, you will not be able to display the images to the users without uploading them to the server. Displaying images from file system is considered a security risk.
EDIT: To remove the unused images, you can create a thread to run a cleanup routine to which will delete them from the upload directory regularly.
Yes, using Silverlight, for example:
In Page.xaml:
<StackPanel x:Name="LayoutRoot" Background="White">
<Button x:Name="btn1" Content="Select image file">
<Image x:Name="img1">
</StackPanel>
and in Page.xaml.cs:
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(Page_Loaded);
}
void Page_Loaded(object sender, RoutedEventArgs e)
{
btn1.Click += new RoutedEventHandler(btn1_Click);
}
void btn1_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == true)
{
Stream s = ofd.File.OpenRead();
BitmapImage bi = new BitmapImage();
bi.SetSource(s);
img1.Source = bi;
s.Close();
}
}
}
Read more here.
Yes, you can using javascript
Javascript:
function showThumbnail(files){
for(var i=0;i<files.length;i++){
var file = files[i]
var imageType = /image.*/
if(!file.type.match(imageType)){
console.log("Not an Image");
continue;
}
var image = document.createElement("img");
var thumbnail = document.getElementById("thumbnail");
image.file = file;
thumbnail.appendChild(image)
var reader = new FileReader()
reader.onload = (function(aImg){
return function(e){
aImg.src = e.target.result;
};
}(image))
var ret = reader.readAsDataURL(file);
var canvas = document.createElement("canvas");
ctx = canvas.getContext("2d");
image.onload= function(){
ctx.drawImage(image,100,100)
}
}
}
var fileInput = document.getElementById("upload-image");
fileInput.addEventListener("change",function(e){
var files = this.files
showThumbnail(files)
},false)
HTML:
<input type="file" id="upload-image" multiple="multiple"></input>
<div id="thumbnail"></div>
You just need the input field and The div to display the thumbnail image, and on change for the input field will call showThumbnail function which will append img inside the "thumbnail" div.
You can do it with Simple javascript...
assign the selected image path.. to image tag prefixing the file://, n it works the way you want it to be