【发布时间】:2019-03-02 14:44:34
【问题描述】:
我想用相机拍摄照片或从照片库中选择照片,也想将图像上传到我的 FTP 服务器。我已经测试了我的 FTP 连接及其工作。但我不知道如何将它上传到我的 FTP 服务器。
请在下面找到我的代码:
takenPicture:any;
constructor(public navCtrl: NavController,
public navParams: NavParams,
public actionsheetCtrl: ActionSheetController,
public platform: Platform,
public loadingCtrl: LoadingController,
private camera: Camera,
public http:Http,
private ftp: FTP,
public alertCtrl: AlertController
) {
}
resimcek(){
const options: CameraOptions = {
quality: 100,
destinationType: this.camera.DestinationType.DATA_URL,
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
saveToPhotoAlbum: false,
allowEdit: true,
targetHeight: 128,
targetWidth: 128
}
this.camera.getPicture(options).then((imageData) => {
// imageData is either a base64 encoded string or a file URI
// If it's base64 (DATA_URL):
this.takenPicture = 'data:image/jpeg;base64,' + imageData;
}, (err) => {
// Handle error
});
this.ftp.connect('myFTPhost', 'myFTPusername', 'myFTPpassword')
.then((res: any) => console.log('Login Correct'))
.catch((error: any) => console.log('Login Failed'));
this.ftp.upload(this.takenPicture,'myFolder/pictures');
}
【问题讨论】:
-
您好,您是否尝试过控制台记录图像 uri 以确保其格式正确?
-
我必须使用真实设备进行测试,所以我使用 alertcontroller 进行控制台日志。我已经尝试过,如果我使用 DATA_URL,我会使用 /blabla/filename.jpg?15371873 但如果我使用 FILE_URL,我会使用更多数字。我想我必须转换为文件拍照
-
好的,如果您的 ftp 调用正常,我建议将 encodingType: this.camera.EncodingType.JPEG 和 mediaType: this.camera.MediaType.PICTURE 添加到您的 cameraOptions 以查看是否有效。我使用 http 调用我的 API 并通过那里连接我的 ftp,但我也使用这些选项并且它们工作正常。
-
@StephenRomero 我会努力的,我会回来的
-
我会再试一次