How to export files in Unity iOS build - ios

I would like to export/share a csv file in my Unity iOS build. The most satisfying functionality would be the sharing pop-up after creating a file, because I don't want to have my users search in /var/mobile/Containers/Data/Application//Documents (like with Application.persistentDataPath).
Is there any solution/plugin for this functionality?
Kind regards Chris

For this purpose, i use https://github.com/ChrisMaire/unity-native-sharing
After adding this as an asset, just call this function:
NativeShare.Share(string body, string filePath, string url, string subject, string mimeType = "text/html", bool chooser, string chooserText)
this supports Android & iOS - and iOS only uses the first 4 parameters - actually you can get it to work with only the filePath attribute - so if you save the csv file (under Application.persistentDataPath), you could simply call:
NativeShare.Share("", Application.persistentDataPath + "/myShinyCsvFile.csv", "", "", "", false, "");

Related

How to store the text in a string variable from a text file in the asset directory?

I am doing some test with xamarin android. I have a text file in the asset folder, that I know how to access to this file:
using (Stream myFile= Assets.Open("myFile.txt"))
{
using (FileStream myDestinationFile= File.Create("myDestinationPath"))
{
myFile.CopyTo(myDestinationFile);
}
}
With this code, I can copy the file to another location, for example, "Personal", so I can edit the file because I know that I can't edit the files in the assets folder.
But I would like to pass the information of the text file directly to a string variable, beacause I don't need to edit the file, just to access to the information and pass this string as parameter of a method.
Is it possible to set a string variable with the information of the text file of the asset folder?
Thanks.
But I would like to pass the information of the text file directly to a string variable, beacause I don't need to edit the file, just to access to the information and pass this string as parameter of a method.
If you want to pass the string from the text file in Assect folder, you could use AssetManager.
Text file:
Set the Build Action to AndroidAssect:
Code:
// Create a new TextView and set it as our view
TextView tv = new TextView(this);
// Read the contents of our asset
string content;
AssetManager assets = this.Assets;
using (StreamReader sr = new StreamReader(assets.Open("TextFile1.txt")))
{
content = sr.ReadToEnd();
}
// Set TextView.Text to our asset content
tv.Text = content;
SetContentView(tv);
Result:

Umbraco 7 Media Upload Issue using drag and drop feature

When I am trying to upload multiple images using Umbraco Drag and Drop functioanlity, I am getting No property type exists with alias umbracoFile. I have custom media type Top Banner with alias name banner. When I upload the image, it is using the custom media type as contentTypeAlias. The custom media type doesn't have a property named umbracoFile. So, I need to change this behavior. I need to use default File/Image media type for uploading the image. How I can achieve it?
I have created a new Media Type 'Top Banner'(Alias:Banner) and properties on Banner media type
Title(TextString)
Banner Image(Image Cropper)
Image(FIleUpload)
Link(Content Picker)
Subtitle((TextString))
VideoLink (TextString)
Centered(checkbox)
Logo(FIleupload)
Is Black Layout for Link Text(checkbox)
If I am adding a property umbracoFile(Property Type : FileUpload) into Banner Media type, the files are getting uploaded and no error is coming.
Exception Details:
No property type exists with alias umbracoFile.
Stack Trace:
at Umbraco.Core.IO.MediaFileSystem.GetProperty(IContentBase content, String propertyTypeAlias)
at Umbraco.Core.IO.MediaFileSystem.SetUploadFile(IContentBase content, String propertyTypeAlias, String filename, Stream filestream)
at Umbraco.Core.Models.ContentExtensions.SetValue(IContentBase content, String propertyTypeAlias, String filename, Stream filestream)
at Umbraco.Web.Editors.MediaController.<PostAddFile>d__26.MoveNext()
These are the Media types
Ok, so. What's happening is that Umbraco tries to determine what the media type is in a couple of ways - first, on the Client side in JavaScript it checks to see what Media Types are allowed in the particular folder you're adding files to.
If you have a recent version of Umbraco (since around November last year), it should be giving you the option to choose which Media Type to upload the files to if you've got more than one allowed type for the folder you're uploading to, otherwise it will silently choose Image or File depending on the extension of the file you're uploading.
The error you're getting may indicate that you're choosing the custom Banner media type while uploading the files, but it may not be set up with the mandatory fields for it to work.
What are your property Aliases? You've only listed the names and the types. My guess is you haven't got the Image Cropper set up with an alias of umbracoFile, and you should also set up the other media aliases as labels similar to the Image media type.
As per Robert's comment I have updated the \Umbraco\lib\ng-file-upload\ng-file-upload.min.js file(line number 185 for unminified file).
if (h == "Banner") {// my custom media type alias is Banner
var regexp = /(?:\.([^.]+))?$/;
var ext = regexp.exec(a.file.name)[1];
ext = ext.toLowerCase();
var imageExtensions = ["png", "jpeg", "gif","jpg"];
if (imageExtensions.indexOf(ext)>-1) {
h = "Image";
}
var fileExtensions = ["pdf", "doc", "gif", "xls", "xlsx", "odt", "ods", "ppt", "pptx", "txt", "zip", "svg", "csv"];
if (fileExtensions.indexOf(ext) > -1) {
h = "File";
}
console.log(ext);
}

How to avoid photos from being replaced Firebase Storage [duplicate]

With the new Firebase API you can upload files into cloud storage from client code. The examples assume the file name is known or static during upload:
// Create a root reference
var storageRef = firebase.storage().ref();
// Create a reference to 'mountains.jpg'
var mountainsRef = storageRef.child('mountains.jpg');
// Create a reference to 'images/mountains.jpg'
var mountainImagesRef = storageRef.child('images/mountains.jpg');
or
// File or Blob, assume the file is called rivers.jpg
var file = ...
// Upload the file to the path 'images/rivers.jpg'
// We can use the 'name' property on the File API to get our file name
var uploadTask = storageRef.child('images/' + file.name).put(file);
With users uploading their own files, name conflicts are going to be an issue. How can you have Firebase create a filename instead of defining it yourself? Is there something like the push() feature in the database for creating unique storage references?
Firebase Storage Product Manager here:
TL;DR: Use a UUID generator (in Android (UUID) and iOS (NSUUID) they are built in, in JS you can use something like this: Create GUID / UUID in JavaScript?), then append the file extension if you want to preserve it (split the file.name on '.' and get the last segment)
We didn't know which version of unique files developers would want (see below), since there are many, many use cases for this, so we decided to leave the choice up to developers.
images/uuid/image.png // option 1: clean name, under a UUID "folder"
image/uuid.png // option 2: unique name, same extension
images/uuid // option 3: no extension
It seems to me like this would be a reasonable thing to explain in our documentation though, so I'll file a bug internally to document it :)
This is the solution for people using dart
Generate the current date and time stamp using:-
var time = DateTime.now().millisecondsSinceEpoch.toString();
Now upload the file to the firebase storage using:-
await FirebaseStorage.instance.ref('images/$time.png').putFile(yourfile);
You can even get the downloadable url using:-
var url = await FirebaseStorage.instance.ref('images/$time.png').getDownloadURL();
First install uuid - npm i uuid
Then define the file reference like this
import { v4 as uuidv4 } from "uuid";
const fileRef = storageRef.child(
`${uuidv4()}-${Put your file or image name here}`
);
After that, upload with the file with the fileRef
fileRef.put(Your file)
In Android (Kotlin) I solved by combining the user UID with the milliseconds since 1970:
val ref = storage.reference.child("images/${auth.currentUser!!.uid}-${System.currentTimeMillis()}")
code below is combination of file structure in answer from #Mike McDonald , current date time stamp in answer from # Aman Kumar Singh , user uid in answer from #Damien : i think it provides unique id, while making the firebase storage screen more readable.
Reference ref = firebaseStorage
.ref()
.child('videos')
.child(authController.user.uid)
.child(DateTime.now().millisecondsSinceEpoch.toString());

ios application Localization

How can I set ios application supported languages?
e.g I use NSDate to get current day. If the device language is other than my supported languages NSDateFormatter returns "day" in device's language but I want to get in English if I don't support that language.
I know there is a way to get day in specific language using NSLocal but I don't want to do that way because I need to convert other strings as well.
The Apple documentation covers this pretty clearly. I know all you need is the word "day", but the following will help you include any word for any language if you do as follows:
1) You need to place all of the words (Strings) in your application into a single .swift file. Each word should be returned in a function that converts this string into the localized string per the device's NSLocal set in the device settings:
struct Localization {
static let all: String = {
return getLocalized("All")
}()
static let allMedia: String = {
return getLocalized("All Media")
}()
static let back: String = {
return getLocalized("Back")
}()
// ...and do this for each string
}
2) This file should also contain a static function that will convert the string:
static func getLocalized(_ string: String) -> String {
return NSLocalizedString(string, comment: "")
}
Here, the NSLocalizedString( method will do all of the heavy lifting for you. If will look into the .XLIFF file (we will get to that) in your project and grab the correct string per the device NSLocale. This method also includes a "comment" to tell the language translator what to do with the "string" parameter you passed along with it.
3) Reviewing all of the strings that you placed in your .swift file, you need to include each of those into an .XLIFF file. This is the file that a language expert will need to go over and include the proper translated word per string in the .XLIFF. As I stated before, this is the file that once included inside your project, the NSLocalizedString( method will search this file and grab the correct translated string for you.
And that's it!

Create and download word file from template in MVC

I have kept a word document (.docx) in one of the project folders which I want to use as a template.
This template contains custom header and footer lines for user. I want to facilitate user to download his own data in word format. For this, I want to write a function which will accept user data and referring the template it will create a new word file replacing the place-holders in the template and then return the new file for download (without saving it to server). That means the template needs to be intact as template.
Following is what I am trying. I was able to replace the placeholder. However, I am not aware of how to give the created content as downloadable file to user. I do not want to save the new content again in the server as another word file.
public void GenerateWord(string userData)
{
string templateDoc = HttpContext.Current.Server.MapPath("~/App_Data/Template.docx");
// Open the new Package
Package pkg = Package.Open(templateDoc, FileMode.Open, FileAccess.ReadWrite);
// Specify the URI of the part to be read
Uri uri = new Uri("/word/document.xml", UriKind.Relative);
PackagePart part = pkg.GetPart(uri);
XmlDocument xmlMainXMLDoc = new XmlDocument();
xmlMainXMLDoc.Load(part.GetStream(FileMode.Open, FileAccess.Read));
xmlMainXMLDoc.InnerXml = ReplacePlaceHoldersInTemplate(userData, xmlMainXMLDoc.InnerXml);
// Open the stream to write document
StreamWriter partWrt = new StreamWriter(part.GetStream(FileMode.Open, FileAccess.Write));
xmlMainXMLDoc.Save(partWrt);
partWrt.Flush();
partWrt.Close();
pkg.Close();
}
private string ReplacePlaceHoldersInTemplate(string toReplace, string templateBody)
{
templateBody = templateBody.Replace("#myPlaceHolder#", toReplace);
return templateBody;
}
I believe that the below line is saving the contents in the template file itself, which I don't want.
xmlMainXMLDoc.Save(partWrt);
How should I modify this code which can return the new content as downloadable word file to user?
I found the solution Here!
This code allows me to read the template file and modify it as I want and then to send response as downloadable attachment.

Resources