2016-12-16 18 views
0

기본 모듈 내에서 티타늄으로 저장된 파일에 액세스하려면 어떻게해야합니까? 제 코드에서는 카메라로 찍은 사진 (Ti.Media)을 파일로 저장합니다. 그런 다음 모듈에서 동일한 파일을 읽으려고합니다. nativePath을 모듈의 메서드에 전달 중입니다. 하지만, 내 모듈에서 파일을 찾을 수 없습니다 오류가 계속. 카메라 성공 콜백에서 티타늄/Android는 기본 모듈의 티타늄에서 생성 된 파일에 액세스합니다.

,이 코드가 있습니다

// earlier in the code 
var tiexif = require('com.me.tiexif'); 

Ti.Media.showCamera({ 
    success: function(event) { 
     console.log("TIEXIF: showCamera.success()"); 
     anImageView.image = event.media; // works 
     if (Ti.Filesystem.hasStoragePermissions()) { 
      console.log("TIEXIF: hasStoragePermissions"); 
      var file = Titanium.Filesystem.getFile(Ti.Filesystem.externalStorageDirectory, 'testphoto.jpg'); 
      console.log("TIEXIF: nativePath: " + file.nativePath); 
      file.write(event.media); 
      someUILabel.text = tiexif.getExifOrientation(file.nativePath); 
     } else ... 
    }, ... 
}) 

을 나는 로그에서 볼 :

[INFO] TIEXIF: showCamera.success() 
[ERROR] File: fail readDirectory() errno=20 
[ERROR] File: fail readDirectory() errno=13 
[ERROR] File: fail readDirectory() errno=13 
[ERROR] File: fail readDirectory() errno=13 
[INFO] TIEXIF: hasStoragePermissions 
[INFO] TIEXIF: nativePath: file:///storage/emulated/0/com.me.exiftest/testphoto.jpg 
[WARN] ExifInterface: Invalid image. 
[WARN] ExifInterface: java.io.FileNotFoundException: file:/storage/emulated/0/com.me.exiftest/testphoto.jpg: open failed: ENOENT (No such file or directory) 

내가 함께 시도 externalStorageDirectory, applicationDataDirectory, tempDirectoryapplicationCacheDirectory 모두와 같은 결과. 내가 리소스 폴더에서 파일을 열 그것을 사용하고

private String getPathToApplicationAsset(String assetName) { 
    // The url for an application asset can be created by resolving the specified 
    // path with the proxy context. This locates a resource relative to the 
    // application resources folder 

    String result = resolveUrl(null, assetName); 
    return result; 
} 

// ... 
String imageSrc = options.getString("image"); 
// ... 
String url = getPathToApplicationAsset(imageSrc); 
TiBaseFile file = TiFileFactory.createTitaniumFile(new String[] { url }, false); 

:

답변

0

이 내가 파일에 이미지 경로를 변환하는 방법입니다. 아직 외부 파일로 시도하지 않았습니다.

파일을로드 할 때 모듈 코드를 표시 할 수 있습니까? https://github.com/freshheads/fh.imagefactory/blob/master/android/src/fh/imagefactory/ImagefactoryModule.java#L66 특히 표시된 기능 :

편집이 프로젝트를 보라 EXIF ​​정보에 대한 파일을 사용합니다. 경로를 변환합니다 (스트립 요소)

+0

ExifInterface를 사용하려고합니다. 생성자는 문서에서 파일 이름을 나타내는 String을 허용합니다. 나는 그것이 파일 경로를 의미한다고 가정하고 있었지만 아마도 앱의 데이터 디렉토리와 관련된 이름 일 것입니다. https://developer.android.com/reference/android/media/ExifInterface.html#ExifInterface(java.lang.String) – skypanther

+0

아 좋아, 파일을 열고 exif에 액세스하는 fh.imagefactory에 대한 링크를 추가했습니다. 정보 (파일 부분을 지울 것입니다.) 그게 너에게 도움이 될거야. – miga

+0

감사합니다. 신입 사원 레포에 대한 링크는 훌륭합니다. 모듈을 Ti 개발자가 쉽게 사용할 수 있도록 앱 사이드를 만드는 것보다 낫습니다. – skypanther

2

file:/ 접미사를 제거하십시오. 티타늄 특정 소재입니다. Android의 경로는 /로 시작합니다.

+0

그랬어! 나는 nativePath.replace ('file :', '') .replace (/ \/\/g/'/')'를 내 모듈로 전달하고 파일에 액세스 할 수 있습니다. 감사! – skypanther