コード例 #1
0
    /// <summary>
    /// Returns the paths of all the files present in the folder
    /// Note - upload size must be less than MaxUploadSize
    /// </summary>
    /// <param name="folderPath">Folder Path</param>
    /// <param name="uploadSize">Passint the size of all file in Folder as out param</param>
    /// <returns>List of all the file paths present in given folder</returns>
    List <string> GetUploadFileList(string folderPath, out long uploadSize)
    {
        List <string>  filePaths    = new List <string>();
        Stack <string> dirs         = new Stack <string>();
        long           uploadLength = 0;

        if (FileBrowserHelpers.DirectoryExists(folderPath))
        {
            dirs.Push(folderPath);
        }

        while (dirs.Count > 0)
        {
            string            currentDir = dirs.Pop();
            FileSystemEntry[] allEntries = FileBrowserHelpers.GetEntriesInDirectory(currentDir);
            foreach (FileSystemEntry entry in allEntries)
            {
                if (entry.IsDirectory)
                {
                    dirs.Push(entry.Path);
                }
                else
                {
                    filePaths.Add(entry.Path);
                    uploadLength += FileBrowserHelpers.GetFilesize(entry.Path);
                    Debug.Log("File : " + entry.Path);
                }
            }
        }

        uploadSize = uploadLength;
        return(filePaths);
    }
コード例 #2
0
 /// <summary>
 /// Uploads file to server, if it is folder Zips the folder - Not used in case of upload to AmazonS3.
 /// Note - As the backend server supports only upload to AmazonS3 this is never called
 /// </summary>
 /// <param name="dataPath">Path of file/folder to be uploaded</param>
 public void UploadToServer(string dataPath)
 {
     if (FileBrowserHelpers.DirectoryExists(dataPath))
     {
         string zipPath = Path.Combine(Application.persistentDataPath, "Temp.zip");
         ZipUtility.CompressFolderToZip(zipPath, null, dataPath);
         if (FileBrowserHelpers.GetFilesize(zipPath) < MaxUploadFileSize)
         {
             StartCoroutine(UploadFileToServer(zipPath, true));
         }
         else
         {
             DisplayUploadErrorMessage("File size is too large. It must be less than 50MB.");
         }
     }
     else
     {
         StartCoroutine(UploadFileToServer(dataPath, false));
     }
 }
コード例 #3
0
    /// <summary>
    /// Tells whether the user selected folder/file is valid i.e contains supported file format and checks file size.
    /// </summary>
    /// <param name="selectedPath">Path of file/folder user wants to upload</param>
    /// <param name="errorMessage">If any error pass error message</param>
    /// <returns>True if file/folder is valid else False</returns>
    public bool IsValidUpload(string selectedPath, out string errorMessage)
    {
        if (FileBrowserHelpers.DirectoryExists(selectedPath))
        {
            FileSystemEntry[] allFiles = FileBrowserHelpers.GetEntriesInDirectory(selectedPath);
            foreach (FileSystemEntry entry in allFiles)
            {
                if (!entry.IsDirectory)
                {
                    string uploadFileExtension = entry.Extension.ToLower();
                    if (uploadFileExtension == TypeGLTF || uploadFileExtension == TypeGLB)
                    {
                        errorMessage = null;
                        return(true);
                    }
                }
            }
            errorMessage = "glTF/glb type file not found in selected folder.";
            return(false);
        }
        else
        {
            string uploadFileName = FileBrowserHelpers.GetFilename(selectedPath).ToLower();
            if (uploadFileName.EndsWith(TypeGLTF) || uploadFileName.EndsWith(TypeGLB))
            {
                if (FileBrowserHelpers.GetFilesize(selectedPath) < MaxUploadFileSize)
                {
                    errorMessage = null;
                    return(true);
                }
                else
                {
                    errorMessage = "File size is too large. It must be less than 50MB.";
                    return(false);
                }
            }

            errorMessage = "File selected is not glTF or glb.";
            return(false);
        }
    }