Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component, OnInit } from "@angular/core";
- import { ImageAsset } from "tns-core-modules/image-asset/image-asset";
- import { ModalDialogParams } from "nativescript-angular/modal-dialog";
- import { UslugaGaleriaService } from "../usluga-galeria.service";
- import { Image } from "tns-core-modules/ui/image/image";
- import * as bgHttp from "nativescript-background-http";
- import * as systemPlikow from "tns-core-modules/file-system";
- import { ImageSource } from "tns-core-modules/image-source/image-source";
- @Component({
- selector: "ns-zatwierdz-galeria",
- templateUrl: "./zatwierdz-galeria.component.html",
- styleUrls: ["./zatwierdz-galeria.component.css"]
- })
- export class ZatwierdzGaleriaComponent implements OnInit {
- obraz: string;
- public zadania: bgHttp.Task[] = [];
- private plik: string;
- private url: string;
- private licznik: number = 0;
- private sesja: any;
- public events: { eventTitle: string, eventData: any }[] = [];
- constructor(
- private galeria: UslugaGaleriaService,
- private params: ModalDialogParams,
- ) {
- this.obraz = galeria.newImgPath;
- this.url = "https://127.0.0.1";
- this.sesja = bgHttp.session("image-upload");
- // this.plik = systemPlikow.path.normalize(systemPlikow.knownFolders.currentApp().path);
- }
- wyslijZdjecie(){
- const nazwa = this.obraz.substr(this.obraz.lastIndexOf("/") + 1);
- console.log("Nazwa ", nazwa);
- const opis = `${nazwa}(${++this.licznik})`;
- console.log("Opis ", opis);
- const request = {
- url: this.url,
- method: "POST",
- headers: { //to są nagłówki wysyłane do serwera
- "Content-Type": "application/octet-stream",
- "File-Name": nazwa
- },
- description: opis,
- androidAutoDeleteAfterUpload: false,
- androidNotificationTitle: 'Rozpoznawanie tablic',
- };
- console.log(nazwa);
- console.log(opis);
- console.log(request);
- let zadanie: bgHttp.Task;
- let lastEvent = "";
- zadanie = this.sesja.uploadFile(this.obraz, request);
- console.log(zadanie);
- function onEvent(e) {
- if (lastEvent !== e.eventName) {
- // suppress all repeating progress events and only show the first one
- lastEvent = e.eventName;
- } else {
- return;
- }
- this.events.push({
- eventTitle: e.eventName + " " + e.object.description,
- eventData: JSON.stringify({
- error: e.error ? e.error.toString() : e.error,
- currentBytes: e.currentBytes,
- totalBytes: e.totalBytes,
- body: e.data,
- responseCode: e.responseCode
- })
- });
- }
- zadanie.on("Wysyłanie w toku", onEvent.bind(this));
- zadanie.on("Błąd", onEvent.bind(this));
- zadanie.on("responded", onEvent.bind(this));
- zadanie.on("Wysyłanie ukończone", onEvent.bind(this));
- lastEvent = "";
- this.zadania.push(zadanie);
- }
- showPath(){
- console.log("Aja",this.obraz);
- console.log("Plik: ", this.plik);
- }
- ngOnInit() {}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement