# Trying to remove Parse-Swift dependency and implement file upload myself results in Invalid file upload (code 130)

**URL:** <https://community.parseplatform.org/t/trying-to-remove-parse-swift-dependency-and-implement-file-upload-myself-results-in-invalid-file-upload-code-130/3007>\
**Category:** ParseSwift SDK\
**Created:** [October 22, 2022, 10:28pm UTC](https://community.parseplatform.org/t/trying-to-remove-parse-swift-dependency-and-implement-file-upload-myself-results-in-invalid-file-upload-code-130/3007 "2022-10-22T22:28:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JohnRoxMySox](https://community.parseplatform.org/letter_avatar_proxy/v4/letter/j/91b2a8/32.png) [@JohnRoxMySox](https://community.parseplatform.org/u/JohnRoxMySox)\
**Post date:** [October 22, 2022, 10:28pm UTC](https://community.parseplatform.org/t/trying-to-remove-parse-swift-dependency-and-implement-file-upload-myself-results-in-invalid-file-upload-code-130/3007/1 "2022-10-22T22:28:39Z")

</div>

Hello,

For some reason, I have been asked to remove Parse dependency from my target, but our backend/DB still relies on it.

With Parse-Swift, I was BTW using this code to save a file to our DB:

```
try ParseFile(
    name: url.lastPathComponent,
    localURL: url
).save()

```

On the new version of my app, I am using _Alamofire_ and _Moya_ for HTTP requests purposes. Here is how I defined the file upload endpoint:

```auto
import Moya

var apiProvider: MoyaProvider<APIService> {
    return MoyaProvider<APIService>()
}

enum APIService {
    case fileUpload(URL)
}

extension APIService: TargetType {
    var baseURL: URL {
        return URL(string: "https://my.url.com/1/")!
    }
    
    var headers: [String : String]? {
        switch self {
        case .fileUpload:
            return [
                "X-Parse-Application-Id": PARSE_APPLICATION_ID,
                "X-Parse-Client-Key": PARSE_CLIENT_KEY,
                "X-Parse-Session-Token": USER_SESSION_TOKEN
            ]
    }
    
    var method: Moya.Method {
        return .post        
    }
    
    var path: String {
        switch self {
        case .fileUpload(let fileURL):
            return "files/" + fileURL.lastPathComponent
        }
    }
    
    var task: Moya.Task {
        switch self {
        case .fileUpload(let fileURL):
            return .uploadFile(fileURL)
        }
    }
}

```

And here is how I call this from the app (`url` being a local URL fetched from `PHPickerViewControllerDelegate`’s _didFinishPicking_):

```
public static func upload(_ url: URL) {
    apiProvider.request(.fileUpload(url)) { result in
        switch result {
        case .success(let resp):
            break
        case .failure(let err):
            break
        }
    }
}

```

I even compared this request’s call from the `ParseFile.save()` one, but I can’t find a reason explaining why I get this error, because both `URLRequests` are the same. The error I get:

> “code”: 130  
> “error”: “Invalid file upload.”

Do you have any idea that could explain this?

Thank you for your help

---

<div class="post-metadata">

**Author:** ![cbaker6](https://community.parseplatform.org/user_avatar/community.parseplatform.org/cbaker6/32/114_2.png) [@cbaker6](https://community.parseplatform.org/u/cbaker6)\
**Post date:** [October 23, 2022, 1:53am UTC](https://community.parseplatform.org/t/trying-to-remove-parse-swift-dependency-and-implement-file-upload-myself-results-in-invalid-file-upload-code-130/3007/2 "2022-10-23T01:53:06Z")

</div>

You should probably change your subject to REST API or something similar since you are no longer using the Swift SDK. You can try looking through the REST documentation and compare what you are encoding to the server:

[https://docs.parseplatform.org/rest/guide/#files](https://docs.parseplatform.org/rest/guide/#files)

---

<div class="post-metadata">

**Author:** ![JohnRoxMySox](https://community.parseplatform.org/letter_avatar_proxy/v4/letter/j/91b2a8/32.png) [@JohnRoxMySox](https://community.parseplatform.org/u/JohnRoxMySox)\
**Post date:** [October 23, 2022, 1:14pm UTC](https://community.parseplatform.org/t/trying-to-remove-parse-swift-dependency-and-implement-file-upload-myself-results-in-invalid-file-upload-code-130/3007/3 "2022-10-23T13:14:48Z")

</div>

Hi @cbaker6 and thank you for your answer, I’ll check that.
