Azure Blob Storage BlockBob - Replaced File Not Shown - c#

I am using Azure blob storage in my project.And when I am trying to update an existing file, if the new file name is different from the current file name it will be updated and shown through the url. But the case is if the new file has a different name from the current file name, yes it will be updated but it will not be shown through the url. When I meant through the URL it means through the browser. And it is not being cached by the browser. I tried clearing browser cached and even used a different browser.
The URL is - https://cubictechdemo.blob.core.windows.net/media/Cache%202017_12062017111606.pdf
But still if I passed a query like https://cubictechdemo.blob.core.windows.net/media/Cache%202017_12062017111606.pdf?xxx
it will give me the updated file.
And however it would be downloaded through blockBlob.DownloadToStream() method. The url shows the old file and the downloadToStream gives me the updated file.
I don't know why this is happening. I am using UploadFromStream method. I can only get the new file if i passed some query.
CloudBlockBlob blockBlob = container.GetBlockBlobReference(blobName);
blockBlob.UploadFromStream(fileInput);
blockBlob.FetchAttributes();
Does anybody know why that is? Thank You.

Related

What should I be saving locally when I use Azure blob storage?

I'm using Azure Blob Storage to allow users to upload files from a web app.
I've got them uploading into a container, but I'm not sure what would be best to save on the web app's database since there are multiple options.
There is a GUID for the file, but also a URL.
The URL can be used to get to the file directly, but is there a risk that it could change?
If I store the file GUID I can use that to get the other details of the file using an API, but of course that's and extra step compared to the URL.
I'm wondering what best practices are. Do you just store the URL and be done with it? Do you store the GUID and always make an extra call whenever a page loads to get the current URL? Do you store both? Is the URL something constant that can act just as good as a GUID?
Any suggestions are appreciated!
If you upload any file on azure blob it will give you Url to access it which contains three part
{blob base url}/{Container Name}/{File Name}
e.g
https://storagesamples.blob.core.windows.net/sample-container/logfile.txt
SO you can save Blob base url and container name in config file and only the file name part in data base.
and at run time you can create whole url and return it back to user.
So in case if you are changing blob or container you just need to change it in config file.

Read contents JSON file sitting on webserver from c# code behind

I am trying to read the contents of a JSON file sitting in my github pages repository.
I can navigate and see the file contents in my browser if I specify the url.
If I use the code here:
http://www.codeproject.com/Tips/397574/Use-Csharp-to-get-JSON-Data-from-the-Web-and-Map-i?msg=4615047#xx4615047xx
It claims to "just work", but it doesn't.
All I get back is:
<html><frameset><frame src="URL-TO-JSON-FILE"></frameset></html>
How am I supposed to read the json file and get its contents back as a string. I am using c#?
Once I get the JSON string back I can do the processing I need to do in c#.
EDIT:
According to rawgithub.com those types of urls are not to be used for production. I need this for production. How do production website read remote JSON files that are located on a webserver?
Thank you
Sometimes in github, if you wish to use code from a repository, you must change the url to raw.github.com/ or click on the raw button and use this url.

Fetching the username who last modified or created the file

Is it possible to get the name of the user who just pasted a file into a folder?
A brief overview of what I am trying to do:
My application keeps watch on a folder for new files every 10 minutes. If it finds any new file it will upload that file via FTP to a specified location.
I would like to know who dropped this file into the folder. Please note that this could be different from the person who created the file.
Thanks
Nishant
The identity of the user modifying a file is not stored in the NTFS Change Journal, but you could use auditing of file access as suggested in this related post.

Accessing http://< someserver.com/logs:<someportnumber> > in client side using c# code

I have a scenario in my mind .. I need validations/suggestions from Stack over flow !! :)
There is a (remote)apache server hosting this URL "http://someserver.com/logs/log.txt:4041" .When i hit this URL in IE it opens a page containing log.txt in a file-folder-directory structure (after authentication).
Is there any way to get the attributes of the log.txt (attributes what i mean is file creation date,file modification date,file size etc..).
What I am planning to do is to write a code in C#.net(in the client) using system.IO namespace and using the fileinfo class and use
FileInfo fi = new FileInfo(pathname);
fi.CreationTime.toString() to retrieve the file creation time.
This is successful for files that exists in local directories in my hard drive!! .
Is it possible to use the same code for retrieving the information about the file that exists in the server that is accessed using the URL "http://someserver.com/logs/log.txt:4041" ?? if yes should i give the URL in my pathename ?
Take it for granted that i have access to the server by authentication..
You can try to inspect the data in WebResponse.Headers. The web server will send some date/time information of the file with the response. This may however not be what you expect depending on the web server you're calling and whether the page you are loading is a script or a file on disk. Settings of the web server will also influence the details returned.
You will not be able to use FileInfo method for items retrieved from http. However if the directory that the file that you are getting served to you is accessible from a share of from samba you could use this method.

Web File Properties

Is it possible to get file properties of a web file. ie: PDF file and get the date and time the PDF file was modified. Thanks.
You're probably looking for the HttpWebResponse.LastModified property.
No, you can't. It's not a file, it's a resource.
When you request it from the server you get a response back. In this case the server uses a file as source for the resource, but it could just as well be something that is just created on the fly. You only get the information that the server chooses to put in the HTML header.
You might however be able to get some more information if the server returns directory information. Then you could request the folder and get a listing back, from which you could parse some information. Note however that it's not certain that the server actually uses the files when you request something from the directory, it could still return something completely different. Also, the directory listing is also a resource, so there is no guarantee that it's relevant either.

Categories

Resources