Giter VIP home page Giter VIP logo

moyamoredemo's Introduction

MoyaMoreDemo

Demo moya upload and download usage examples

只是一个基于 Moya 官方的上传、下载演示 Demo,通过 ServiceProvider 实现如下常用功能:

  • 上传单个文件(带参数)
  • 上传多个文件(带参数)
  • 下载方法(带有赋值参数)
  • 下载方法封装

上传文件使用示例代码:

//需要上传的文件
let file1URL = Bundle.main.url(forResource: "hangge", withExtension: "png")!
let file1Data = try! Data(contentsOf: file1URL)
let file2URL = Bundle.main.url(forResource: "other", withExtension: "png")!
//通过Moya提交数据
ServiceProvider.request(
    .uploadMultipleFileName(value1: "hangge", value2: 10, file1Data: file1Data, file2URL: file2URL),
    progress:{
        progress in
        //实时答打印出上传进度
        print("当前进度: \(progress.progress)")
}) {
    result in
    if case let .success(response) = result {
        //解析数据
        let data = try? response.mapString()
        print(data ?? "")
    }
}

控制台打印信息:

封装下载 AssetLoader 使用示例代码:

func downloadAssetLoader() {
    let loader = AssetLoader()
    loader.load(asset: .logo) { result in
        switch result {
        case let .success(localLocation):
            print("下载完毕!保存地址:\(localLocation)")
        case let .failure(error):
            print(error)
        }
    }
}

控制台打印信息:

moyamoredemo's People

Contributors

reversescale avatar

Stargazers

 avatar  avatar

Watchers

James Cloos avatar  avatar

Forkers

laohei0304

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.