簡體   English   中英

為什么在Mac OS上FileReferenceList.fileList類型為NULL

[英]Why is FileReferenceList.fileList type NULL on MAC OS

我有一個將文件上傳到服務器的應用程序。 onSelectFile函數中,我檢查文件類型以查看其是否有效。 我也有一個FileFilter ,它限制了用戶可以選擇的內容,但是我想再次檢查他們是否上傳了正確的文件類型。

在PC上,我可以獲得文件的type值,但是在Mac(Safari,Firefox,Chrome)上,我得到NULL。

這是我嘗試獲取類型的函數

// Called when a file is selected
            private function onSelectFile(event:Event):void {
                //let's see if we're dealing with a new album or an existing album
                var arrFoundList:Array = new Array();
                // Get list of files from fileList, make list of files already on upload list
                for (var i:Number = 0; i < _arrUploadFiles.length; i++) {
                    for (var j:Number = 0; j < _refAddFiles.fileList.length; j++) {
                        if (_arrUploadFiles[i].name == _refAddFiles.fileList[j].name) {
                            arrFoundList.push(_refAddFiles.fileList[j].name);
                            _refAddFiles.fileList.splice(j, 1);
                            j--;
                        }
                    }
                }

                if (_refAddFiles.fileList.length >= 1) {                
                    for (var k:Number = 0; k < _refAddFiles.fileList.length; k++) { 

                        var fileType:String = _refAddFiles.fileList[k].type;
                        Alert.show("File type: " + fileType.toString() + " | name: " + _refAddFiles.fileList[k].name); //fileType is always NULL on Mac
                        var validTypes:Array = new Array(".jpg", ".jpeg", ".gif", ".png", ".JPG", ".JPEG", ".GIF", ".PNG"); 

                        if (validTypes.indexOf(fileType.toLowerCase()) < 0)
                        {
                            Alert.show("The file type: " + fileType + " is not valid (file: " + _refAddFiles.fileList[k].name + "). Valid types are .jpg, .gif, and .png", "Invalid File Type");
                            continue;
                        }

                        //start the upload for each file    
                        var item:OneFile= new OneFile();
                        item.fileName=_refAddFiles.fileList[k].name;
                        item.fileSize=_refAddFiles.fileList[k].size;

                        item.file=_refAddFiles.fileList[k];
                        _bytesTotal+=_refAddFiles.fileList[k].size;

                        if (existingalbum.selected) 
                        {
                            item.album=albums.selectedItem.@aid;
                        }
                        fileList.addChild(item);
                        _files.addItem(item);
                        _numFiles++;

                    }

                    startUpload();
                }
                else
                {
                    Alert.show("No files were added to the list to be uploaded.");
                }               
                if (arrFoundList.length >= 1) {
                    Alert.show("The file(s): \n\n• " + arrFoundList.join("\n• ") + "\n\n...are already on the upload list. Please change the filename(s) or pick a different file.", "File(s) already on list");
                }
                else{ // some comment

                }

            }

這是我發現的解決方法:

public static function extractFileType(fileName:String):String {
  var extensionIndex:Number = fileName.lastIndexOf(".");
  if (extensionIndex == -1) {
    return "";
  } else {
    return "." + fileName.substr(extensionIndex + 1,fileName.length);
  }
}

http://www.josh-ho.com/as3-mac-filereference-type-workaround/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM