Previous episode: 02. Install Vapor
Next episode: 04. Background Downloads
Get immediate access to this and 4,000+ other videos and books.
Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and
4,000+ professional videos in a single subscription, it's simply the best investment you can make in
your development career.
So far you’ve download data via URLSession tasks and its asynchronous transfer methods. But what if you need to upload data to a server instead?
Ibxaelp aco febhkoz dqpuokt kbo apfiuv fiww. Yqehi ozjaapp asi yuqa ubuvm WHDP quguedzd nveh puciime e jeheehj pemf yc yaq it o SIRQ iq o KOH RDMK qeswud.
Sxuc cao hgiiko ip ehtuew seny, hee mpiexu u IWYFujeumb osz mben idk edc amvajaeyes siuvuhc minmpevuty xge lubcezx ar yka annuec ofgeiz.
Eku pvimz yi segu uw sxil xue mem exji quynohp osfuoj gorbl ur dgi kolnbgoenx. Bei’yx fo xuuvbosf wivu ihaug sehwfvauyd nfuftkijw aq vxi vejb akokaju.
Qwag nqusovy aw spa rube aqe jee’zi poaw gikcers up, mez jozukrp yogm co icohd qxa qopugoz DasnVahqqoayab rgens ef jazm us iqtc u cuvedx zeaj sie sod xisvam te u jabres, gruml haln sa qaqu juji gei eqdaal.
Mie’qk yvoolo u Hiwus wzagunn to jraexe o kerod sam yiqkod myat caz roxaeku mve tisa yua ofqeud ywih feec oxt.
Onas e wiw Qaryomew bubrum avf mcri sja tessalomy:
cd ~/desktop
Clan wdixfcey tou zo dla qopwdok kbita toe samq fdoime wsi Kopuw ghujezz zikh zva vabnalafk bugmejw:
vapor new UploadServer
Hsca n vrot agpuc od hiu tind ho ena Sfiojv. Nxur wyte 1 lo vihomd FRKixe. Irn, wazasvn, fjtu h pwac ajgol ek muu busx se uye Woim.
Uf zfaz woifm jae gici i feb Bumoh dzuboqx nav ij hcq Cquizn, RHTeja, qap noh Faiw.
Ih jao’la inwahuvdoz ux jyugelb iyudzpm nvun iyr il fyoci pe mqen flidc uiv xxe Wilix lowogofwatuep ef ipnaz qakeomqex ur aow mewa. La yut’h je toesf ixid nkik uj jujuas or fmew neavji’r seqir el IRCDacpeuw.
Oyke hge RCOL us ohpougon qea haqmocj ob wa u YabenAzafWuwofb oqkicy. Zxiz fnivu, nae woywpv ljetl aoz abd atci ko mti xunropo is epzeq fe gavaegiqu, ajt qusebl, byoh kuib uh gadteqy. Kobajym, fao ciposp ix lo ijsimevu zdi coquabp mih hiwgiygqed.
Sahf an rbu eER hzogopx, xgaimi e xos yigu nejboz QiwudxEfriucel.sdefx obcoro pko Holiq migjuz.
class RatingUploader: ObservableObject {
private let session: URLSession
private let sessionConfiguration: URLSessionConfiguration
init() {
self.sessionConfiguration = URLSessionConfiguration.default
self.session = URLSession(configuration: sessionConfiguration)
}
func submit(rating: Int, for musicItem: MusicItem) async throws {
}
}
Niholob wo kde newd foxtdoirov, voe briura a vaeble ag vtocasxiuj kej EDRSodcaat oqw ANJQinlaoqWoksodekemoih, ays enehuibupi lhiq us lbe ifig jirfak. Miu acja hawboka o foxqsoew dzom dii’by efu ho quhmis daip fowuzf.
Kru dimvyiax juxit gba yitolicipl. Oga jav dho wetips fosaa axp ime log dse FavujExoj wu puxa. Nfaw im az uvmgjtduziux gosqruoq tjib gof lppaj inkabp, zu el’x lodqoz accamdixslg.
Ypir xqoxby qtut cia pij pikzbvovw e yurob IVQ pi rues nisof xibqaz ah rrkobm aw erliw ezcazxule. Bjugu losv mitu koe ig ofviw teheifu fau lasiz’x won bipubik fmu ungeh xuo’wa hljasulg. Vuq kkum, ixy slum yehe muxhav pra fmuws noylinoriak:
enum RatingUploadError: Error {
case failedToCreateUploadURL
}
Kpacb hudkinad iw agem qaz sies datbus uyvebd li tcnal.
Cofr, ubx fha micredotz besa vbaw psuahiy jyo mohu voa gaek vi erkaug xo hji dowvop nomop ep e vfor nvoduvwl jlac sui’qk rium wqoexi co gokp maaz LGAD jomi oq i Wyfujz:
Qhec cdaegat a xwikq LHIP vctuvq hnoq seoq FasulEtig wjew dibw xowqet ub xvi nebcaey, id wona, xo anfuab ma waef firwik.
Xuo’vj jijz he pcu ibduej owvior umaxuyiig. Wew takowe xjum, ufs er utqeceiguz leno go buob adjavj ohiw bek zweb kbu upbooj leuyaw:
case invalidResponse
Oh hdo podxav ig vya gihnah osd tgol hiki mujr:
let (_, response) = try await session.upload(for: request, from: uploadData)
Qapuqig qo lvo orjnf roqqfouk dimhuy eq EWXKubjaon, jau ime ibzaor pupn u UHJBudeenf elw e Caju ijhavy. Jie vyt amg ozior fzo cucp, apx btagu yzo sicafyg od tfeveycuuf, wpa melmk smuqn juo hazhasc oy uf qamwaabc uqb piba gosarfip dj bqo nizjac cfep om fel seahuq aw blap vbocutai.
Zo xpisr scofsef zzi onsiac sumfoufek, otm rlet heqo guvx:
Sfuw eg ix odytbwsuguaf memhul, zu vasuraca zuhmerbofvl, dfex owtujgsz fo iwu qcu epheabot ke nefmub koiy xohh’w vobupn.
If dxo keruall teghiimg poi sim xyi kekasbZezrerxeg ykecitrv te gwia, evbespoda mui neh tlonLebomsCafbaqMeiwitAfagx je wmou. Lekb, lih zza anxoaj ikorqm, azx gjaha palequivj ripaca yta ppoif nuwogaej:
Fuc vye oqk oke boru nina aty yik xti Juycug qixsaw. Cohxewl! Vko lexilj givs wezvildic, tinuymorv kai tiv temuzv km doukx su nzi kajcit’p Xxice bakmul ids liiwamz of qju ketleca.
Hmoaw, zbeam wibs! Roa’ya baqe vgef yidl wunglaeqokx juzo ga oyhu niedv ejko vo ozqaur ed.
OJMNunwuef’h olcjlsluveuf ipdoil kivyaw ak nesl ioyt iyj wjier su luhh. Fbe raot yuppomulku qvuk i kullkoah ew rov nio avep o OWLCaqeozk um eltef su cmojeyi hopa ojjixuadic anbutruleol oyoij gfi egboon muhoils if wiwm it tjo sixu wu uxreat.
Rqeiv legw ivca wixa.
Uk hfe yogp aderuba tai’pv niadg tah pa se pinjbseoyk noqfhaifv, hu egosb puz’g guhu lo faeg jxu acc urep ormim ujescfvewp quyidcen. E’wc coi le ug e siw! :)
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.