I am working on a unity project and I need to save a certain screenshot from my game to a container in azure storage.
I already configured my azure account and created the container.
I managed to take the screenshot and save it in a directory on my computer but whenever I try to save it to my storage I cant because it does not found it. I go to that directory and I can see the screenshot.
This is how I do the screenshot part:
public void TappedCaptureScreenshot()
{
string filename = string.Format("{0}.png", DateTime.UtcNow.ToString("yy-MM-dd-HH-mm-ss-ff"));
Debug.Log("aca estoy 0 " + filename);
localPath = Screenshot.Capture(filename);
Debug.Log("local path " + localPath);
isCaptured = true;
//label.text = "Capture as: " + localPath;
}
This is how I save the picture:
public void TappedSave()
{
byte[] imageBytes = File.ReadAllBytes(localPath);
PutImage(imageBytes);
}
private void PutImage(byte[] imageBytes)
{
string filename = Path.GetFileName(localPath);
Debug.Log("Aca estoy 2 " + filename);
//label.text = "Put " + filename;
StartCoroutine(blobService.PutImageBlob(PutImageCompleted, imageBytes, container, filename, "image/png"));
}
Then whenever I clic a certain button, both functions are called.
This is the error I get:
FileNotFoundException: Could not find file "C:..\20-02-23-21-12-59-06.png"
I think the error has something to do with image bytes but I do not know why. Any suggestions?
Related
I want upload an image file to project's folder but I have an error in my catch:
Could not find a part of the path 'C:\project\uploads\logotipos\11111\'.
What am I do wrong? I want save that image uploaded by my client in that folder... that folder exists... ah if I put a breakpoint for folder_exists3 that shows me a true value!
My code is:
try
{
var fileName = dados.cod_cliente;
bool folder_exists = Directory.Exists(Server.MapPath("~/uploads"));
if(!folder_exists)
Directory.CreateDirectory(Server.MapPath("~/uploads"));
bool folder_exists2 = Directory.Exists(Server.MapPath("~/uploads/logo"));
if(!folder_exists2)
Directory.CreateDirectory(Server.MapPath("~/uploads/logo"));
bool folder_exists3 = Directory.Exists(Server.MapPath("~/uploads/logo/" + fileName));
if(!folder_exists3)
Directory.CreateDirectory(Server.MapPath("~/uploads/logo/"+fileName));
file.SaveAs(Server.MapPath("~/uploads/logo/" + fileName+"/"));
}
catch(Exception e)
{
}
Someone knows what I'm do wrong?
Thank you :)
Try this:
string targetFolder = HttpContext.Current.Server.MapPath("~/uploads/logo");
string targetPath = Path.Combine(targetFolder, yourFileName);
file.SaveAs(targetPath);
Your error is the following:
bool folder_exists3 = Directory.Exists(Server.MapPath("~/uploads/logo/" + fileName));
if(!folder_exists3)
Directory.CreateDirectory(Server.MapPath("~/uploads/logo/"+fileName));
You check if a directory exists, but you should check if the file exists:
File.Exists(....);
You need filename
file.SaveAs(Server.MapPath("~/uploads/logo/" + fileName+"/" + your_image_fillename));
Remove the last part of the path to save you have an extra "/"
It should be
file.SaveAs(Server.MapPath("~/uploads/logo/" + fileName);
Also you do not have a file extension set.
Platform: Unity 2020.1.0f1
I have a weird problem while creating a little game that is meant to download videos from a remote URL to Application.PersistentDataPath and play them in the Unity3D-VideoPlayer using the "RenderTexture"-way by pressing a button for a specific video.
In the editor EVERYTHING works fine...
On IOS EVERYTHING works fine...
On Android (no matter which version) only the video from the asset folder is played properly. Accessing a downloaded file from Application.persistentDataPath is simply showing nothing on Android...
Things I checked (in addition to simple blindness):
"External Write Permission" > forced everything on "internal"... not working
Using Path.Combine() and/or "string filepath = ..."
"Different Video Formats" > nope... the asset video is playing properly without transcoding (it is h.264 AVC, 650x650px, 30fps - AAC Audio, 44,1kHz, Bps 32)
Sample code below, the test scene can also be downloaded here:
http://weristaxel.de/upload/Videotest.unity
http://weristaxel.de/upload/VideotestController.cs
Video in Unity asset folder:
https://corolympics.azurewebsites.net/assets/game1howto.mov
What am I missing?
public void PlayFromPersistent()
{
// NOT WORKING ON ANDROID
VideoPlayer VideoHowTo = VideotestCanvas.transform.Find("VideoPlayer").GetComponent<VideoPlayer>();
string filePath = Application.persistentDataPath + "/game2howto.mov";
VideoHowTo.Stop();
VideoHowTo.url = filePath;
VideoHowTo.source = VideoSource.Url;
DebugText.text = "VideoHowTo.url = " + filePath;
VideoHowTo.Prepare();
VideoHowTo.Play();
}
public void PlayFromAssets()
{
// WORKING ON ANDROID
VideoPlayer VideoHowTo = VideotestCanvas.transform.Find("VideoPlayer").GetComponent<VideoPlayer>();
VideoHowTo.Stop();
VideoHowTo.clip = assetVideo;
VideoHowTo.source = VideoSource.VideoClip;
DebugText.text = "VideoHowTo.clip set - original path " + assetVideo.originalPath;
VideoHowTo.Play();
}
public void DownloadVideo()
{
// THIS DOWNLOADS A TEST VIDEO TO "persistentDataPath"...
string url = "https://corolympics.azurewebsites.net/assets/game2howto.mov";
Debug.Log("Downloading " + url);
var uwr = new UnityWebRequest(url, UnityWebRequest.kHttpVerbGET);
string filename = url.Split('/').Last();
string path = Path.Combine(Application.persistentDataPath , filename);
uwr.downloadHandler = new DownloadHandlerFile(path);
uwr.SendWebRequest();
DebugText.text = "Download to " + path + " finished";
}
public void AddListener()
{
// NOT WORKING ON ANDROID - THIS ADDS A LISTENER TO AN EMPTY BUTTON TO EMULATE THE TARGET BEHAVIOUR
Button button = VideotestCanvas.transform.Find("FromPersistentListenerButton").GetComponent<Button>();
Color blueColor = new Color32(52, 152, 219, 255);
button.GetComponent<Image>().color = blueColor;
button.onClick.AddListener(() =>
{
VideoPlayer VideoHowTo = VideotestCanvas.transform.Find("VideoPlayer").GetComponent<VideoPlayer>();
string filePath = Application.persistentDataPath + "/game2howto.mov";
VideoHowTo.Stop();
VideoHowTo.url = filePath;
VideoHowTo.source = VideoSource.Url;
DebugText.text = "VideoHowTo.url = " + filePath;
VideoHowTo.Play();
});
}
If you're still stuck i would try creating an independant function for when you add the listener event. So it would be something like 'button.onClick.AddListener(() => IndFunction())' instead of creating a new instance each time. I was stuck on something similar a while back and i created an editable script for each button to store the info for each one and set each according to a list of image links and image names.
Im currently building a Windows service that will be used to create backups of logs. Currently, the logs are stored at the path E:\Logs and intent is to copy the contents, timestamp their new folder and compress it. After this, you should have E:\Logs and E:\Logs_[Timestamp].zip. The zip will be moved to C:\Backups\ for later processing. Currently, I am using the following to try and zip the log folder:
var logDirectory = "E://Logs";
var timeStamp = DateTime.Now.ToString("yyyyMMddHHmm");
var zippedFolder = logDirectory + "_" + timeStamp + ".zip";
System.IO.Compression.ZipFile.CreateFromDirectory(logDirectory, zippedFolder);
While this appears to create a zip folder, I get the error Windows cannot open the folder. The Compressed (zipped) Folder E:\Logs_201805161035.zip is invalid.
To address any troubleshooting issues, the service is running with an AD account that has a sufficient permission level to perform administrative tasks. Another thing to consider is that the service kicks off when its FileSystemWatcher detects a new zip folder in the path C:\Aggregate. Since there are many zip folders that are added to C:\Aggregate at once, the FileSystemWatcher creates a new Task for each zip found. You can see how this works in the following:
private void FileFoundInDrops(object sender, FileSystemEventArgs e)
{
var aggregatePath = new DirectoryInfo("C://Aggregate");
if (e.FullPath.Contains(".zip"))
{
Task task = Task.Factory.StartNew(() =>
{
try
{
var logDirectory = "E://Logs";
var timeStamp = DateTime.Now.ToString("yyyyMMddHHmm");
var zippedFolder = logDirectory + "_" + timeStamp + ".zip";
ZipFile.CreateFromDirectory(logDirectory, zippedFolder);
}
catch (Exception ex)
{
Log.WriteLine(System.DateTime.Now.ToString() + " - ERROR: " + ex);
}
});
task.Dispose();
}
}
How can I get around the error I am receiving? Any help would be appreciated!
I am very new to C#. I am doing some self studies. I did one small CRUD App using Windows Form Application. It's working fine. Now I want to do one like that in WPF. I realized, some functions, methods are not same as WFA.
Now I want to know how to save the uploaded image to a custom folder.
I have created folder in my Solution called Uploaded. I know how to Upload, Resize the images. Now I want to save this resized image to that Cutome Folder.
Here is my event.
private void SaveBtn_Click(object sender, RoutedEventArgs e)
{
string imagepath = ProfilePicURL.Text;
string picname = imagepath.Substring(imagepath.LastIndexOf('\\'));
//Rename the file as per the user first and last name
picname = FirstName.Text.Replace(" ", String.Empty) + "_" + LastName.Text.Replace(" ", String.Empty);
}
string imagepath = ProfilePicURL.Text;
var imageFile = new System.IO.FileInfo(imagepath);
if (imageFile.Exists)// check image file exist
{
// get your application folder
var applicationPath=System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
// get your 'Uploaded' folder
var dir=new System.IO.DirectoryInfo(System.IO.Path.Combine(applicationPath,"uploaded"));
if(!dir.Exists)
dir.Create();
// Copy file to your folder
imageFile.CopyTo(System.IO.Path.Combine(dir.FullName,string.Format("{0}_{1}",
FirstName.Text.Replace(" ", String.Empty),
LastName.Text.Replace(" ", String.Empty))));
}
I am making an application called Profiler to store some people's profiles, and will use a database to store the profile photo's path.
This is my FindPhoto button (to upload the profile photo):
private void btnFindPhoto_Click(object sender, EventArgs e)
{
ofdFindPhoto.Title = "Select a Photo ";
ofdFindPhoto.InitialDirectory = #"D:\Desktop";
ofdFindPhoto.FileName = "";
ofdFindPhoto.Filter = "JPEG Image|*.jpg|GIF Image|*.gif|PNG Image|*.png|BMP Image|*.bmp";
ofdFindPhoto.Multiselect = false;
if (ofdFindPhoto.ShowDialog() != DialogResult.OK) { return; }
// Show the recently uploaded photo on profile
picProfilePhoto.ImageLocation = ofdFindPhoto.FileName;
}
When the user clicks the button to save the profile, I get the txtName.Text, txtPhone.Text, txtDescription.Text and photo path to save to the database. I want to use something like this to save the photo path:
string photoPath = Application.StartupPath + #"\Photos\" + txtName.Text +
Path.GetExtension(ofdFindPhoto.FileName);
This should generate some path like:
Drive:\InstalledPath\Profiler\Username.jpg (or whatever extension)
In short, I need to place a folder inside the application's root, but this folder should be created on install or first run (preferably that I can use on debug, too).
if(!Directory.Exists(Application.StartupPath + #"\Photos"))
Directory.CreateDirectory(Application.StartupPath + #"\Photos");
try this in program.cs.It checks for folder when the application in opened
if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "Profiles"))
{
Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "Profiles");
}
Application.Run(new form1());