Uploading images to Windows Server and making them available publicly - image

I am trying to upload images in my windows server VM "hosted on-premise" and make these images available publicly like www.example.com/imageFolder/cat.png.
This VM has IIS enabled (I am not sure if IIS is related here) and it is assigned a URL and available publicly.
Aside from any programming languages or frameworks, I just want to know if storing the image in the server and making it available via a link is possible? If so, how can I achieve it?
To clarify further:
I believe what I want is very simple and tedious.
Consider the following workflow:
Run an API that has end points to receive images on the server.
Store the messages in the server.
Return the link that points to the picture.
I want to know the procedure from the windows server side like
Do I need to set certain properties on the folder where I will store the images?
Do I need to add a site to show the images back to the user?
I am a developer and I am new to the Windows Server & IIS so I may not have all the fundamentals.

I made a sample by using ASP.NET MVC5. You can follow this article to upload image in MVC5 application.
Upload Images on Server Folder Using ASP.NET MVC
Then, I do some changes so that it can display the url of images..
[HttpPost]
public ActionResult Upload(HttpPostedFileBase file)
{
Uri requestUri = HttpContext.Request.Url;
string baseUrl = requestUri.Scheme + Uri.SchemeDelimiter + requestUri.Host + (requestUri.IsDefaultPort ? "" : ":" + requestUri.Port);
if (ModelState.IsValid)
{
try
{
if (file != null)
{
string path = Path.Combine(Server.MapPath("~/Images"), Path.GetFileName(file.FileName));
file.SaveAs(path);
}
string link = baseUrl + "/Images/" + file.FileName;
ViewBag.FileStatus = "File uploaded successfully.";
//Return the url of image
ViewBag.FileLink = link;
}
catch (Exception e)
{
ViewBag.FileStatus = "Error while file uploading. Error message is "+e.Message;
}
}
return View("Index");
}
Index.cshtml add this to show url.
<div class="col-md-offset-2 col-md-10 text-success">
#ViewBag.FileLink
</div>
Don't forget to add a folder named Images to store images. After publishing, you also need to add it in published folder, otherwise error message will show that cannot find folder.
It works well.

Related

How can I access the images folder from code behind

I have an image on the images folder of a SharePoint 2013 site. I want to access this folder (and this image) to load it on a carousel, but I don't know where is it and how I can access to it.
Can anyone helps me? Thanks!
I upload an screenshot, hope it helps.
We can get the image URL like below:
Then use the URL in to show the image.
<img src="/sites/team/PublishingImages/Capture32.PNG"/>
If you want to get image using C# in Server, we can get images library and get all list items.
using (SPSite site = new SPSite("http://sp2013/sites/team"))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["Images"];
foreach (SPListItem item in list.Items)
{
Console.WriteLine(item.File.ServerRelativeUrl);
}
}
}

MVC big file download

I am using ASP.net MVC 4.0. I want to download a file after clicking a download button/a link. The problem is that the file is big and I want to show a 'wait image' while downloading. How do i do it? I am getting the file as a stream? Should I use HTPResposneMessage with web-api or FileStreamResult with MVC? The issue is I want to be notified when the download finishes.
My file is being downloaded with a code as below:
public FileStreamResult Download(Guid id)
{
.......
return this.File(cab, "application/octet-stream", id + ".cab");
}
I want to show a spinner in javascript before beginning the download. My code is as follows:
self.IsDownloading(true);
var url = '/Download/' + id;
window.location = url;
self.IsDownloading(false);
But IsDownloading(false) is being executed before downloading the full file. How to make sure that it is done after the full file is downloaded?

Has anyone been able to get ABCPDF (HTML Conversion) working on azure websites

Webforms Page Code behind
XSettings.InstallRedistributionLicense("REDACTED");
var theDoc = new Doc();
theDoc.HtmlOptions.Engine = EngineType.Gecko;
theDoc.Rect.Inset(72, 144);
theDoc.Page = theDoc.AddPage();
int theID = theDoc.AddImageUrl("http://www.woot.com/");
while (true)
{
theDoc.FrameRect(); // add a black border
if (!theDoc.Chainable(theID))
break;
theDoc.Page = theDoc.AddPage();
theID = theDoc.AddImageToChain(theID);
}
for (int i = 1; i <= theDoc.PageCount; i++)
{
theDoc.PageNumber = i;
theDoc.Flatten();
}
Response.Buffer = false;
Response.AddHeader("Content-Disposition", "inline; filename=\"rept.pdf\"");
Response.ContentType = "application/pdf";
theDoc.Save(Response.OutputStream);
Response.Flush();
should work pretty well.. but get
Failed to add HTML: RPC to Gecko engine process failed.Remote process terminated unexpectedly.
Running Full trust
have in bin folder
XULRunner Folder and everything from C:\Program Files (x86)\WebSupergoo\ABCpdf .NET 9.0\ABCGecko
ABCGecko.dll
ABCpdf.dll
ABCpdf9-32.dll
Package / Publish Web All files in this project folder
You are not allowed to run external processes from within your Windows Azure Website as this would pose a risk in the shared infrastructure.
See this post by a MSFT employee or that post where the same employee talks about other restrictions concerned with native APIs.
You can verify that the problem is related to the externally launched Gecko by not adding the HTML image to the document. For me the creation of the PDF progressed further but failed because of the missing license.
It looks like you would have to find a fully managed/.NET HTML rendering engine (if converting a website to PDF is your use-case) or hope that reserved-mode web sites gain the right to execute native/external processes.
There are full ABCpdf Azure deployment guides here:
http://www.websupergoo.com/support-azure-abcpdf.htm

bits , sharpBits.net

I using in my project BITS - Background Intelligent Transfer Service for send file with larg size. Using SharpBITS.NET in C# code.
I want to upload file from server to client. I now note the sides.
-------------client side---------------
static void Main(string[] args)
{
string local = #"I:\a.mp3";
string destination = "http://192.168.56.128/BitsTest/Home/FileUpload";
string remoteFile = #destination;
string localFile = local;
if (!string.IsNullOrEmpty(localFile) && System.IO.File.Exists(localFile))
{
var bitsManager = new BitsManager();
var job = bitsManager.CreateJob("uploading file", JobType.Upload);
job.NotificationFlags = NotificationFlags.JobErrorOccured | NotificationFlags.JobModified |
NotificationFlags.JobTransferred;
job.AddFile(remoteFile, localFile);
job.Resume();
job.OnJobError += new EventHandler<JobErrorNotificationEventArgs>(job_OnJobError);
}
}
This is a simple console application. the local -- path the file that I want to send, destination -- the path is receiver it is remote server.
When I run program the job.Error take mi follow --- "The server's response was not valid. The server was not following the defined protocol. Resume the job, and then Background Intelligent Transfer Service (BITS) will try again. -- BG_E_HTTP_ERROR_200 .-2145845048, 0x801900C8"
For Client (receiver) i have the follow code: It is Mvs 3 small project and I View only action
where to go by our destination path.
public ActionResult FileUpload()
{
try
{
HttpPostedFileBase file = Request.Files[0];
file.SaveAs(System.IO.Path.Combine(Server.MapPath("/BitsTest/"), file.FileName));
}
catch
{ }
/*System.IO.File.Move(Server.MapPath("/BitsTest/bin/aa.png"), Server.MapPath("/BitsTest/Content/aa.png"));*/
}
But FileUpload action thas not recevie file. I don't know how I can receive file in client Side.
As you can see, I used HttpPostedFileBase for recive file but that is not working.
My host server is Windows server 2008 r2 and I done needed steps for BITS. For more information you can visit the follow site http://technet.microsoft.com/en-us/library/cc431377.aspx ---- How to Configure Windows Server 2008 for Configuration Manager 2007 Site Systems.
So I don't know what doing that I can receive file in host server.You can tell me what you can do.
With a stateless methdology like the one web applications use, there is no connection to the server once the response is completed. You can poll the server from the client side, but the client is not listening for the server to send additional bits.
In "the past" you could set up ActiveX controls, Java applets, etc (Silverlight today?) to continue to listen, but this is not straight web style development.
HTML5 expands your options, if you are willing to use the websocketAPI. As with all parts of HTML5, you have some risk using these bits for implementation as not all browsers have adopted the "standard" yet (adoption expected to be complete in the next 10-12 years:->).

How to upload a file in joomla?

Hi i am making a simple component in joomla having name image detail and i have to upload that image how can i upload image from backend. which one is better using extension or make custom. can you please share any good article for it. i have searched many more but due to lack of idea on joomla cannot find. hope you genius guys help me.
thanks i advance
Joomla Component for the exact scenario of your requirement will be very hard to find out. So you've two options:
1. Make your own component
2. Customize other similar type of component like gallery component
For uploading file from joomla component on admin if you're making your own component:
1. Just use move_uploaded_file php function.
2. copy this code, for joomla's standard fxn :
function upload($src, $dest)
{
jimport('joomla.client.helper');
$FTPOptions = JClientHelper::getCredentials('ftp');
$ret = false;
$dest = JPath::clean($dest);
$baseDir = dirname($dest);
if (!file_exists($baseDir)) {
jimport('joomla.filesystem.folder');
JFolder::create($baseDir);
}
if ($FTPOptions['enabled'] == 1) {
jimport('joomla.client.ftp');
$ftp = & JFTP::getInstance($FTPOptions['host'], $FTPOptions['port'], null, $FTPOptions['user'], $FTPOptions['pass']);
$dest = JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $dest), '/');
if (is_uploaded_file($src) && $ftp->store($src, $dest))
{
$ret = true;
unlink($src);
} else {
JError::raiseWarning(21, JText::_('WARNFS_ERR02'));
}
} else {
if (is_writeable($baseDir) && move_uploaded_file($src, $dest)) { // Short circuit to prevent file permission errors
if (JPath::setPermissions($dest)) {
$ret = true;
} else {
JError::raiseWarning(21, JText::_('WARNFS_ERR01'));
}
} else {
JError::raiseWarning(21, JText::_('WARNFS_ERR02'));
}
}
return $ret;
}
If you want to use other's component and edit it according to need, download it:
http://prakashgobhaju.com.np/index.php?option=com_showcase_gallery&view=items&catid=1&Itemid=64
Remember it's a gallery component.
Uploading any file be it an image on your Joomla site is something which is so simple, and can be done using either the web based FTP and or the desktop FTP services like filezilla but only when you have saved the file you want to upload. Using the web based way, you need to log in to your host for example 000webhost, locate the file manager option, click on it and enter your domain username and password. Then go to public_html folder , create a new folder for your photos or images and click on upload. Locate your image and click on the tick link to start uploading.
Using the desktop way, you will need to unzip your file to add to joomla, open your FTP client like filezilla, locate the file on local host, input your log in details as provided by your host and once you are logged in to your account through filezilla, locate where you want to add the file and click on upload.
You can find a similar tutorial with regard here http://www.thekonsulthub.com/how-tos/how-to-upload-joomla-with-filezilla-to-your-hosting-servers-cpanel/ {entire thing}
Please please please make sure you use the filtering available in the MediaHelper. Specifically never trust uploaded images, always check first that they are valid file types, then that they are in the list of approved types of files listed in your global configuration, that the names do not contain html or javascript, and that the files themselves do not contain code. In particular I would recommend the MediaHelper::canUpload method which will check the majority of these things for you. If anything you should be checking even more strongly. Also make sure that you are checking whether the user has permission to upload. If anything you should make the checking even more restrictive. Use the APIs that joomla gives you, such as the built in media field.

Resources