Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle name and filepath issues
Browse files Browse the repository at this point in the history
Name was an UUID for images & videos, now using real name
Also removing file:// prefix in filepaths as it made RNFS
unable to retrieve the file, and silently creating empty files
acezard committed Nov 21, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 9f6c286 commit 54328e9
Showing 2 changed files with 17 additions and 13 deletions.
20 changes: 10 additions & 10 deletions ios/CozyShare/ShareViewController.swift
Original file line number Diff line number Diff line change
@@ -90,12 +90,12 @@ class ShareViewController: UIViewController {
if error == nil, let url = data as? URL, let this = self {
// this.redirectToHostApp(type: .media)
// Always copy
let fileExtension = this.getExtension(from: url, type: .video)
let newName = UUID().uuidString
let newPath = FileManager.default
.containerURL(forSecurityApplicationGroupIdentifier: "group.\(this.hostAppBundleIdentifier)")!
.appendingPathComponent("\(newName).\(fileExtension)")
let copied = this.copyFile(at: url, to: newPath)
let newName = this.getFileName(from :url)
let newPath = FileManager.default
.containerURL(forSecurityApplicationGroupIdentifier: "group.\(this.hostAppBundleIdentifier)")!
.appendingPathComponent(originalFileName) // Use the original file name
let copied = this.copyFile(at: url, to: newPath)

if(copied) {
this.sharedMedia.append(SharedMediaFile(path: newPath.absoluteString, thumbnail: nil, duration: nil, type: .image))
}
@@ -120,12 +120,12 @@ class ShareViewController: UIViewController {
if error == nil, let url = data as? URL, let this = self {

// Always copy
let fileExtension = this.getExtension(from: url, type: .video)
let newName = UUID().uuidString
let newName = this.getFileName(from :url)
let newPath = FileManager.default
.containerURL(forSecurityApplicationGroupIdentifier: "group.\(this.hostAppBundleIdentifier)")!
.appendingPathComponent("\(newName).\(fileExtension)")
.containerURL(forSecurityApplicationGroupIdentifier: "group.\(this.hostAppBundleIdentifier)")!
.appendingPathComponent(originalFileName) // Use the original file name
let copied = this.copyFile(at: url, to: newPath)

if(copied) {
guard let sharedFile = this.getSharedMediaFile(forVideo: newPath) else {
return
10 changes: 7 additions & 3 deletions src/app/domain/upload/services/upload.ios.ts
Original file line number Diff line number Diff line change
@@ -32,9 +32,13 @@ export const uploadFile = async ({
files: [
{
name: filename,
filename: filename,
filetype: mimetype,
filepath
filename,
// We need to remove the file:// prefix or the upload will be empty but successful (silent error)
// Doing it at the last moment is preferrable to avoid breaking other platforms or side effects
filepath: filepath.startsWith('file://')
? filepath.replace('file://', '')
: filepath,
filetype: mimetype
}
],
binaryStreamOnly: true,

0 comments on commit 54328e9

Please sign in to comment.