count image hash(md5) in adobe air - image

I use HTML+JAVASCRITP+CSS develop desktop software in adobe air platform
I download md5.js that count md5 value as same php md5 value
air.filestream function read location of file and send to md5.js to count hash ,normal file(js,php,css,txt) can count as same php md5 value, but count image file get wrroy hash,the image isn't change.
var fileStream = new air.FileStream();
var target = new air.File(file.nativePath);
fileStream.open(target , air.FileMode.READ);
var str = fileStream.readMultiByte(target.size,'utf-8'); alert(window.md5(str));

You should use this library that does reading binary data.
Then, unzip the swc and get the swf file to a lib folder in your app path.
You must check the xml file to get the qualified name of the md5 function you want to use
(.by.blooddy.crypto.MD5.hashBytes(data) )
Add an script include line on the html header
<script src="lib/library.swf" type="application/x-shockwave-flash"></script>
and you can use the function trought the window.runtime object:
hash = window.runtime.by.blooddy.crypto.MD5.hashBytes(data);
and this hash will be the same you can get with a md5 in php.
By the way you must read the file using readBytes instead of readMultiByte.
adobe link (Using ActionScript libraries within an HTML page)

Related

Upload CSV payload to Google Storage using Ruby

I am trying to upload string payload to Google Storage directly using Ruby. But, it seems there's no direct way to do this without creating a temporary file in the disk.
I am using the CSV library to generate a string payload.
Current method suggests to store the string payload in a temporary file and then use code something like below to upload the file to google storage:
require "google/cloud/storage"
storage = Google::Cloud::Storage.new
bucket = storage.bucket bucket_name
file = bucket.create_file local_file_path, file_name
Is there a way to avoid creating a temporary file to upload?
I found the documentation where it states that we can use any File-like object such as StringIO to upload string payload directly.
Here's my code:
require "google/cloud/storage"
storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-todo-app"
bucket.create_file StringIO.new("Hello world!"), "hello-world.txt"
Go to Creating a File section of this link for example
Documentation Link:
https://googleapis.dev/ruby/google-cloud-storage/latest/Google/Cloud/Storage/Bucket.html#create_file-instance_method

Custom file name while keeping extension

Following this part of the docs:
https://laravel.com/docs/5.3/filesystem#file-uploads
I'm trying to store a file (an image) and specify a custom file name, but I don't want to change the extension.
If I do:
$request->file('avatar')->storeAs('avatars', 'custom_file_name');
The file will save as custom_file_name (with no extension), rather than custom_file_name.png).
How can I specify a custom file name while keeping the original file extension?
You can get extension of uploaded file with:
$extension = $request->photo->extension();
And apply it manually to the stored file name.
The UploadedFile class also contains methods for accessing the file's fully-qualified path and its extension. The extension method will attempt to guess the file's extension based on its contents.
https://laravel.com/docs/5.4/requests#files
The code below checks if request has a file by id/name avatar and then stores it with custom_name.{uploaded_files_extension}
if($request->hasFile('avatar')) {
$imgfile = Input::file('avatar');
$custom_name = 'custom_name'.$imgfile->getClientOriginalExtension();
$request->file('avatar')->storeAs('avatars', $custom_name);
}
Just to buttress #alexey-mezenin answer,
you might have issue adding the extension
//get extension
$extension = $request->file('featured_img')->extension();
$request->file('featured_img')->storeAs('/public/album',$post->title.'.'.$extension);
With that you can have a complete code stored in your /storage/public/album

Setting Google Photos date

I uploaded many photos with no EXIF data, but with their date in the name. Google Photos used upload date to sort them. I'd like to use the date in their name to modify them.
So far I tried to use Drive API to change modification date, I can change it but it is not used. I also tried to modify imageMediaMetadata.date, but it seems to be read-only to me.
Code:
function myFunction() {
var files = DriveApp.getFilesByName("IMG-20150402-WA0002_1.jpg")
while (files.hasNext()) {
var file = files.next();
var name = file.getName().toUpperCase();
if (name.indexOf("-WA") > -1) {
if (name.indexOf("IMG-20") == 0 || name.indexOf("VID-20") == 0) {
var y = name.substr(4, 4);
var m = name.substr(8, 2);
var d = name.substr(10, 2);
var file2 = Drive.Files.get(file.getId());
file2.imageMediaMetadata.date = y+"-"+m+"-"+d+"T12:00:00.000Z";
var file3 = Drive.Files.patch(file2, file.getId());
Logger.log(name + " no ok " + file3.imageMediaMetadata.date); // same as file2
}
}
}
I could delete them, modify the original files and re-upload, but before that I'd like to be sure there is no other way.
Thank you.
Perhaps you could programmatically write an EXIF header to the files?
I would also be looking for a convenient way to supply photo date when uploading old photos using the new-ish Google Photos API. My photos do not necessarily have EXIF data; I tried setting the creation/last modified date on one of my JPEGs on my MacOS machines disk, then manually uploading it via the Google Photos web interface and the date of of the JPEG file on local disk becomes the photo's date in Google Photos, as expected. The file has no EXIF data and if did, it would not contain that same date, so apparently the google photos web uploader respects the local filesystem date for the photo.
I then tried to sniff the traffic using Charles Proxy, but apparently the web interface does not use the Google Photos API same way that us external developers would -- it doesnt POST to https://photoslibrary.googleapis.com/v1/uploads or so it seems. So I couldn't reverse engineer that process. Also I couldn't see where the file creation date was passed in.
What would be great is to have a HTTP header in the upload POST request to set this date. I dont see batchCreate (https://developers.google.com/photos/library/reference/rest/v1/mediaItems/batchCreate) method having any means of setting this.

How to download a jpg from web to project folder in MVC3?

Hello everyone I would like to ask How can I download .jpg file from web to my project's folder which I have created "uploads" ?
I'm trying to downlaod youtube thumbnail image to my" uploads" folder.
My controller:
var fileName = Path.GetFileName(http://img.youtube.com/vi/RUgd_GDPhYk/1.jpg);
var path = Path.Combine(Server.MapPath("~/uploads/"), fileName);
file.SaveAs(path);
Take a look at System.Net.WebClient, a .NET class which allows you to make requests for resources via HTTP.
http://msdn.microsoft.com/en-us/library/system.net.webclient(v=vs.100).aspx
Checked example provided.
var client = new System.Net.WebClient();
var uri = "http://img.youtube.com/vi/RUgd_GDPhYk/1.jpg";
// Here, we're just using the same filename as the resource we're after.
// You may wish to change this to include extra stuff because you'll
// inevitably run into a naming clash - especially with stuff like 1.jpg
var targetFilename = Path.GetFileName(uri);
client.DownloadFile(uri,
Path.Combine(Server.MapPath("~/uploads"), targetFilename));

How to create the path to desktop for the target user..in C#.net

I am developing image extraction application in .net using C# in VS2010.
i have created a path ,where the image will be extracted.But this path is specific to my system.
string image1 = "c:\\Users\\Raghu\\Desktop\\r.bmp";
I want a path which should be general i.e when the project will be deployed ,the output file should be extracted in Target Users desktop.
how create a folder on desktop and and all my extracted files goes in it.
Any ideas! please help me!!
Next code will return path to the desktop of current user:
Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
So, in your case it would be
string desktop = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
string image1 = System.IO.Path.Combine(desktop, "r.bmp");
Environment.SpecialFolder (http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx) contains many definitions of system folder paths. Take a look which you need.
You would use the DesktopDirectory for Environment.SpecialFolder. Something like this:
public static string GetDesktopDirectory()
{
return Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
}
Then using the result of that method, you can use Path.Combine to append a file name to it.
var myFilePath = Path.Combine(GetDesktopDirectory(), "r.bmp");
Path.Combine is the general solution for this, as directly concating strings may result in double slashes, etc. This takes care of that for you.

Resources