0

Umbenennen / per Mail senden / Upload Cloudinary

Fast geschafft,

doch bei einer Sache komme ich nicht weiter.  Der Upload zu Cloudinary funktioniert, jedoch hab ich das Problem, dass ich bei Cloudinary, Files mit derselben ID nicht überschreiben kann. Bsp.: Es wurden schon Files hochgeladen, jedoch muss eines geändert werden) Überschreiben ist nicht, es bleibt das schon bei  Cloudinary bestehende File als Rückgabe link. Das "neue" wird nicht gespeichert. Ist ja im Grunde auch gut so. Ich müsste es also vorher löschen und dann erst den Upload starten. (Natürlich nur das betreffende File löschen) Ich hab nur keine Ahnung wie.

Der Auszug für den Upload:

                ---
upload zu Clouinary
                ---;
                let uploadkey := first(select NinoxKeys).text(CloudinaryUpload);
                let cloudikey := first(select NinoxKeys).text(CloudinaryAPI);
                let webhook := first(select NinoxKeys).text(WebhookCloudinary);
                let filesauswahl := [Abrechnung, Bild1, Bild2, Bild3, Bild4, Bild5, Bild6, Bild7, Bild8, Bild9, Bild10];
                for k in filesauswahl do
                    if k != null then
                        let filename := first(split(text(k), "."));
                        let filid := last(split(text(filename), "/"));
                        let data := {
                                file: shareFile(k),
                                folder: "Abrechnungen",
                                upload_preset: uploadkey,
                                public_id: filid,
                                api_key: cloudikey
                            };
                        let response := do as server
                                http("POST", webhook, data)
                            end;
                        if response.result.error then
                            alert(text(response.result.error))
                        else
                            responseAbrechnung := text(response);
                            ---
rückgabe links zuordnen
                            ---;
                            if responseAbrechnung then
                                let zuordnung := last(split(text(response.result.secure_url), "/"));
                                let linkzuordnung := first(split(text(zuordnung), "_"));
                                switch true do
                                case linkzuordnung = "Abrechnung":
                                    linkAbrechnung := text(response.result.secure_url)
                                case linkzuordnung = "Bild1":
                                    linkBild1 := text(response.result.secure_url)
                                case linkzuordnung = "Bild2":
                                    linkBild2 := text(response.result.secure_url)
                                case linkzuordnung = "Bild3":
                                    linkBild3 := text(response.result.secure_url)
                                case linkzuordnung = "Bild4":
                                    linkBild4 := text(response.result.secure_url)
                                case linkzuordnung = "Bild5":
                                    linkBild5 := text(response.result.secure_url)
                                case linkzuordnung = "Bild6":
                                    linkBild6 := text(response.result.secure_url)
                                case linkzuordnung = "Bild7":
                                    linkBild7 := text(response.result.secure_url)
                                case linkzuordnung = "Bild8":
                                    linkBild8 := text(response.result.secure_url)
                                case linkzuordnung = "Bild9":
                                    linkBild9 := text(response.result.secure_url)
                                case linkzuordnung = "Bild10":
                                    linkBild10 := text(response.result.secure_url)
                                default:
                                    alert("fehler in der Zuordnung")
                                end
                            end
                        end
                    end
                end;
                ---

 

Der komplette Aufruf:

---
 prüfen auf maximal größe
---;
let size := MBAbrechnung + MBBild1 + MBBild2 + MBBild3 + MBBild4 + MBBild5 + MBBild6 + MBBild7 +
    MBBild8 +
    MBBild9 +
    MBBild10;
if size > 20 then
    alert("Mailgröße überschritten (max: 20 MB möglich) versenden NICHT möglich! Bitte die Bilder verkleinern und erneut senden.")
else
    ---
 prüfen auf pflichfelder
    ---;
    if Abrechnung = null or 'Abrechnung vom' = null then
        dialog("Abrechnung an VK senden nicht möglich, da keine Abrechnung eingefügt wurde.", "Bitte Abrechnung einfügen! oder Abrechnung vom einfügen", ["OK"])
    else
        if dialog("Abrechnung an VK senden", "bitte mit Ja bestätigen um Abrechnung zu senden", ["Ja", "Nein"]) = "Ja" then
            ---
 START - create Array name of existings ImageFields
Hier die vorhandenen Namen der Bildfelder eintragen.
            ---;
            let vArrFieldNames := ["Abrechnung", "Bild1", "Bild2", "Bild3", "Bild4", "Bild5", "Bild6", "Bild7", "Bild8", "Bild9", "Bild10"];
            "__________________________________________________________________________________";
            ---
 START1 - Get FieldID of ImageFields and create as Array
            ---;
            let myCloud := first(select NinoxKeys).NinoxCloud;
            let vApiKey := first(select NinoxKeys).NinoxAPI;
            let vUrl := ---
 https://{ myCloud }/v1/teams/{ teamId() }/databases/{ databaseId() }/tables/{ tableId(this) }
                ---;
            let vHeader := {
                    Authorization: "Bearer " + vApiKey,
                    'Content-Type': "application/json"
                };
            let vResponse := do as server
                    http("GET", vUrl, vHeader, {}).result.fields
                end;
            let vId := "";
            for i in vResponse do
                let vVerg := i.name;
                for ii in vArrFieldNames do
                    if vVerg = ii then
                        vId := vId + i.id + ","
                    end
                end
            end;
            let vArrImgFldId := slice(split(vId, ","), 0, cnt(split(vId, ",")));
            "__________________________________________________________________________________";
            ---
 START2 - create Array of existings ImageNames
            ---;
            let oName := if Abrechnung and NewName_Image1 then
                    text(last(split(text(Abrechnung), "/")))
                else
                    "Empty"
                end;
            oName := oName + "," +
                if Bild1 and NewName_Image2 then
                    last(split(text(Bild1), "/"))
                else
                    "Empty"
                end;
            oName := oName + "," +
                if Bild2 and NewName_Image3 then
                    last(split(text(Bild2), "/"))
                else
                    "Empty"
                end;
            oName := oName + "," +
                if Bild3 and NewName_Image4 then
                    last(split(text(Bild3), "/"))
                else
                    "Empty"
                end;
            oName := oName + "," +
                if Bild4 and NewName_Image5 then
                    last(split(text(Bild4), "/"))
                else
                    "Empty"
                end;
            oName := oName + "," +
                if Bild5 and NewName_Image6 then
                    last(split(text(Bild5), "/"))
                else
                    "Empty"
                end;
            oName := oName + "," +
                if Bild6 and NewName_Image7 then
                    last(split(text(Bild6), "/"))
                else
                    "Empty"
                end;
            oName := oName + "," +
                if Bild7 and NewName_Image8 then
                    last(split(text(Bild7), "/"))
                else
                    "Empty"
                end;
            oName := oName + "," +
                if Bild8 and NewName_Image9 then
                    last(split(text(Bild8), "/"))
                else
                    "Empty"
                end;
            oName := oName + "," +
                if Bild9 and NewName_Image10 then
                    last(split(text(Bild9), "/"))
                else
                    "Empty"
                end;
            oName := oName + "," +
                if Bild10 and NewName_Image11 then
                    last(split(text(Bild10), "/"))
                else
                    "Empty"
                end;
            let oldName := split(oName, ",");
            "__________________________________________________________________________________";
            ---
 START3 - create Array of existings Imagesuffix
            ---;
            let fEnd := if Abrechnung then
                    replace(extractx(last(split(text(Abrechnung), "/")), "(\.[A-Za-z0-9]+$)"), ".", "")
                else
                    "Empty"
                end;
            fEnd := fEnd + "," +
                if Bild1 then
                    replace(extractx(last(split(text(Bild1), "/")), "(\.[A-Za-z0-9]+$)"), ".", "")
                else
                    "Empty"
                end;
            fEnd := fEnd + "," +
                if Bild2 then
                    replace(extractx(last(split(text(Bild2), "/")), "(\.[A-Za-z0-9]+$)"), ".", "")
                else
                    "Empty"
                end;
            fEnd := fEnd + "," +
                if Bild3 then
                    replace(extractx(last(split(text(Bild3), "/")), "(\.[A-Za-z0-9]+$)"), ".", "")
                else
                    "Empty"
                end;
            fEnd := fEnd + "," +
                if Bild4 then
                    replace(extractx(last(split(text(Bild4), "/")), "(\.[A-Za-z0-9]+$)"), ".", "")
                else
                    "Empty"
                end;
            fEnd := fEnd + "," +
                if Bild5 then
                    replace(extractx(last(split(text(Bild5), "/")), "(\.[A-Za-z0-9]+$)"), ".", "")
                else
                    "Empty"
                end;
            fEnd := fEnd + "," +
                if Bild6 then
                    replace(extractx(last(split(text(Bild6), "/")), "(\.[A-Za-z0-9]+$)"), ".", "")
                else
                    "Empty"
                end;
            fEnd := fEnd + "," +
                if Bild7 then
                    replace(extractx(last(split(text(Bild7), "/")), "(\.[A-Za-z0-9]+$)"), ".", "")
                else
                    "Empty"
                end;
            fEnd := fEnd + "," +
                if Bild8 then
                    replace(extractx(last(split(text(Bild8), "/")), "(\.[A-Za-z0-9]+$)"), ".", "")
                else
                    "Empty"
                end;
            fEnd := fEnd + "," +
                if Bild9 then
                    replace(extractx(last(split(text(Bild9), "/")), "(\.[A-Za-z0-9]+$)"), ".", "")
                else
                    "Empty"
                end;
            fEnd := fEnd + "," +
                if Bild10 then
                    replace(extractx(last(split(text(Bild10), "/")), "(\.[A-Za-z0-9]+$)"), ".", "")
                else
                    "Empty"
                end;
            let fileSuff := split(fEnd, ",");
            "__________________________________________________________________________________";
            ---
 START4 - create Array of new ImageNames
            ---;
            let nName := if NewName_Image1 then NewName_Image1 else "Empty" end;
            nName := nName + "," + if NewName_Image2 then NewName_Image2 else "Empty" end;
            nName := nName + "," + if NewName_Image3 then NewName_Image3 else "Empty" end;
            nName := nName + "," + if NewName_Image4 then NewName_Image4 else "Empty" end;
            nName := nName + "," + if NewName_Image5 then NewName_Image5 else "Empty" end;
            nName := nName + "," + if NewName_Image6 then NewName_Image6 else "Empty" end;
            nName := nName + "," + if NewName_Image7 then NewName_Image7 else "Empty" end;
            nName := nName + "," + if NewName_Image8 then NewName_Image8 else "Empty" end;
            nName := nName + "," + if NewName_Image9 then NewName_Image9 else "Empty" end;
            nName := nName + "," + if NewName_Image10 then NewName_Image10 else "Empty" end;
            nName := nName + "," + if NewName_Image11 then NewName_Image11 else "Empty" end;
            let newName := split(nName, ",");
            "__________________________________________________________________________________";
            ---
 Start5 - create API Urls
            ---;
            let deleteURL := ---
https://{ myCloud }/v1/teams/{ teamId() }/databases/{ databaseId() }/tables/{ tableId(this) }/records/{ number(this) }/files/
                ---;
            let getURL := ---
https://{ myCloud }/v1/teams/{ teamId() }/databases/{ databaseId() }/tables/{ tableId(this) }/records/{ number(this) }/files/
                ---;
            let postURL := ---
https://{ myCloud }/v1/teams/{ teamId() }/databases/{ databaseId() }/tables/{ tableId(this) }/records/{ number(this) }/files/
                ---;
            "__________________________________________________________________________________";
            ---
 Start6 - create API Headers
            ---;
            let deleteHeaders := {
                    Authorization: "Bearer " + vApiKey,
                    'Content-Type': "application/json"
                };
            let getHeaders := {
                    Authorization: "Bearer " + vApiKey,
                    'nx-file': "base64url"
                };
            let postHeaders := {
                    Authorization: "Bearer " + vApiKey,
                    Accept: "multipart/form-data"
                };
            "__________________________________________________________________________________";
            ---
 Start7 - Execute http Requests
            ---;
            for k in range(0, cnt(oldName)) do
                if item(oldName, k) != "Empty" then
                    let response := do as server
                            http("GET", getURL + urlEncode(item(oldName, k)), getHeaders, "")
                        end;
                    let base64File := text(response.result);
                    let filesArray := [{
                                name: item(newName, k) + "." + item(fileSuff, k),
                                value: base64File
                            }];
                    let vBody := {
                            fieldId: item(vArrImgFldId, k)
                        };
                    let PostResponse := do as server
                            formatJSON(http("POST", postURL, postHeaders, vBody, filesArray))
                        end;
                    sleep(500);
                    http("DELETE", deleteURL + urlEncode(item(oldName, k)), deleteHeaders, {});
                    NewName_Image1 := null;
                    NewName_Image2 := null;
                    NewName_Image3 := null;
                    NewName_Image4 := null;
                    NewName_Image5 := null;
                    NewName_Image6 := null;
                    NewName_Image7 := null;
                    NewName_Image8 := null;
                    NewName_Image9 := null;
                    NewName_Image10 := null;
                    NewName_Image11 := null
                else
                    k := k + 1
                end
            end;
            "__________________________________________________________________________________";
            ---
 Mailtext 2 varianten
            ---;
            let mithinweis := ---
<p>Sehr geehrte Damen und Herren,</p><p>anbei die Abrechnung von { text('Abrechnung vom') }.<br><br>Hinweise:<br>{ replace('Hinweise: *** TEXT für MAIL ***', "
", "<br>") }</p><br/>
<p>F&uuml;r R&uuml;ckfragen stehe ich Ihnen jederzeit gerne telefonisch zur Verf&uuml;gung.</p>
<p>
Mit freundlichen Gr&uuml;&szlig;en</p>
<p>i.A. Michael Zub<br />
- Kundenservice -</p>
<p>
Fiebiger &amp; Scheibe GmbH<br />
Grimmstr. 37<br />
01139 Dresden</p>
<p>Tel.: +49 351 417746 - 11<br />
Fax: +49 351 417746 - 15</p>
<p>web: www.fiebiger-scheibe.de<br />
email: ae@fiebiger-scheibe.de</p>
<p>Gesch&auml;ftsf&uuml;hrung<br />
Raymond Fiebiger, Falk Scheibe<br />
Dresden Amtsgericht Dresden HRB 25873<br />
Steuernummer: 203/108/06790
</p>
                ---;
            let ohnehinweis := ---
<p>Sehr geehrte Damen und Herren,</p><p>anbei die Abrechnung von { text('Abrechnung vom') }.<br><br>
<p>F&uuml;r R&uuml;ckfragen stehe ich Ihnen jederzeit gerne telefonisch zur Verf&uuml;gung.</p>
<p>
Mit freundlichen Gr&uuml;&szlig;en</p>
<p>i.A. Michael Zub<br />
- Kundenservice -</p>
<p>
Fiebiger &amp; Scheibe GmbH<br />
Grimmstr. 37<br />
01139 Dresden</p>
<p>Tel.: +49 351 417746 - 11<br />
Fax: +49 351 417746 - 15</p>
<p>web: www.fiebiger-scheibe.de<br />
email: ae@fiebiger-scheibe.de</p>
<p>Gesch&auml;ftsf&uuml;hrung<br />
Raymond Fiebiger, Falk Scheibe<br />
Dresden Amtsgericht Dresden HRB 25873<br />
Steuernummer: 203/108/06790
</p>
                ---;
            ---
 Mail senden Make
            ---;
            let vWebhook := first(select NinoxKeys).WebhookMake;
            let vRecordID := text(number(this));
            let An := 'Aufträge'.Vertragspartner.'Mail für Abrechnung';
            let An1 := 'Aufträge'.Vertragspartner.'2 verkauf';
            let bet := "Abrechnung vom" + " " + 'Abrechnung vom' + "" + " zu KV: " + 'Aufträge'.'KV-Nr.' +
                "/ " +
                'Aufträge'.Name +
                " - " +
                'Aufträge'.Vorname;
            let tex := if 'Hinweise: *** TEXT für MAIL ***' then
                    mithinweis
                else
                    ohnehinweis
                end;
            let data := {
                    RecordID: vRecordID,
                    vMailAn: An,
                    vBetreff: bet,
                    vTextHTML: tex,
                    vto: An1
                };
            let res := do as server
                    http("POST", vWebhook, {
                        'Content-Type': "application/json"
                    }, data)
                end;
            if res.result.error then
                alert(text(res.result.error))
            else
                ---
Datensätze aktualisieren
                ---;
                'versendet?' := true;
                'Versendet am' := today();
                'anfahrt Nr' := 'hilfe anfahrt nr.';
                let me := 'Aufträge';
                let aa := 'Abrechnung vom';
                let dat := now();
                let user := userName();
                let term := 'Aufträge'.'Liefertermin von';
                let text := "Abrechnung zu Liefertermin vom: " + term + " " + "an VK versendet";
                let myR := (create Historie);
                myR.('Änderungsdatum' := dat);
                myR.(Benutzer := user);
                myR.('Aktion oder Info text eingeben' := text);
                myR.('Aufträge' := me);
                Fahrer := text('Aufträge'.'Fahrer wählen');
                'Aufträge'.('Team wählen' := null);
                'Aufträge'.('Fahrer wählen' := null);
                'Aufträge'.(Terminstatus := null);
                'Aufträge'.('Liefertermin von' := null);
                'Aufträge'.('Liefertermin bis' := null);
                for i in select Montageauftrag where 'Aufträge2' = me and 'Eingangsdatum des Montageauftrages' > aa or aa = null do
                    i.(Status := 1)
                end;
                for i in select Montageauftrag where 'Aufträge2' = me and 'Eingangsdatum des Montageauftrages' < aa do
                    i.(Status := 2)
                end;
                for i in select Lieferscheine
                    where 'Aufträge' = me and 'Ausgelagert am' = null and Eingangsdatum < aa or
                    'Aufträge'.'Verknüpft mit Auftrag' = me and 'Ausgelagert am' = null and
                        Eingangsdatum < aa do
                    i.('Ausgelagert am' := aa)
                end;
                let me := this;
                if cnt(select Lieferscheine where 'Aufträge' = me and 'Ausgelagert am' = null) > 0 then
                    'Aufträge'.('Am Lager' := true)
                else
                    'Aufträge'.('Am Lager' := false)
                end;
                let me := this;
                if cnt(select Montageauftrag where 'Aufträge2' = me and Status = 1) > 0 then
                    'Aufträge'.('Auftrag offen' := true)
                else
                    'Aufträge'.('Auftrag offen' := false)
                end;
                if ['Aufträge'.'Lagerbestand da' > 0 or 'Aufträge'.'Lagerbestand da' = 0] and
                            'Aufträge'.'Montageaufrag offen' > 0 and
                        ['Aufträge'.'Abrechnungen gemacht 1' = 0 or 'Aufträge'.'Abrechnungen gemacht 1' > 0] and
                    'Aufträge'.'Liefertermin ja' = 0 then
                    'Aufträge'.(Terminstatus := 1)
                else
                    if 'Aufträge'.'Lagerbestand da' > 0 and 'Aufträge'.'Montageaufrag offen' = 0 and
                        ['Aufträge'.'Abrechnungen gemacht 1' = 0 or 'Aufträge'.'Abrechnungen gemacht 1' > 0] then
                        'Aufträge'.(Terminstatus := 6)
                    else
                        if 'Aufträge'.'Liefertermin ja' > 0 then
                            'Aufträge'.(Terminstatus := 2)
                        else
                            if 'Aufträge'.'Lagerbestand da' = 0 and 'Aufträge'.'Montageaufrag offen' = 0 and
                                'Aufträge'.'Abrechnungen gemacht 1' > 0 then
                                'Aufträge'.(Terminstatus := 7)
                            else
                                if 'Aufträge'.'Lagerbestand da' = 0 and 'Aufträge'.'Montageaufrag offen' = 0 and
                                        'Aufträge'.'Abrechnungen gemacht 1' = 0 and
                                    'Aufträge'.'Liefertermin ja' = 0 then
                                    'Aufträge'.(Terminstatus := 8)
                                end
                            end
                        end
                    end
                end;
                ---
upload zu Clouinary
                ---;
                let uploadkey := first(select NinoxKeys).text(CloudinaryUpload);
                let cloudikey := first(select NinoxKeys).text(CloudinaryAPI);
                let webhook := first(select NinoxKeys).text(WebhookCloudinary);
                let filesauswahl := [Abrechnung, Bild1, Bild2, Bild3, Bild4, Bild5, Bild6, Bild7, Bild8, Bild9, Bild10];
                for k in filesauswahl do
                    if k != null then
                        let filename := first(split(text(k), "."));
                        let filid := last(split(text(filename), "/"));
                        let data := {
                                file: shareFile(k),
                                folder: "Abrechnungen",
                                upload_preset: uploadkey,
                                public_id: filid,
                                api_key: cloudikey
                            };
                        let response := do as server
                                http("POST", webhook, data)
                            end;
                        if response.result.error then
                            alert(text(response.result.error))
                        else
                            responseAbrechnung := text(response);
                            ---
rückgabe links zuordnen
                            ---;
                            if responseAbrechnung then
                                let zuordnung := last(split(text(response.result.secure_url), "/"));
                                let linkzuordnung := first(split(text(zuordnung), "_"));
                                switch true do
                                case linkzuordnung = "Abrechnung":
                                    linkAbrechnung := text(response.result.secure_url)
                                case linkzuordnung = "Bild1":
                                    linkBild1 := text(response.result.secure_url)
                                case linkzuordnung = "Bild2":
                                    linkBild2 := text(response.result.secure_url)
                                case linkzuordnung = "Bild3":
                                    linkBild3 := text(response.result.secure_url)
                                case linkzuordnung = "Bild4":
                                    linkBild4 := text(response.result.secure_url)
                                case linkzuordnung = "Bild5":
                                    linkBild5 := text(response.result.secure_url)
                                case linkzuordnung = "Bild6":
                                    linkBild6 := text(response.result.secure_url)
                                case linkzuordnung = "Bild7":
                                    linkBild7 := text(response.result.secure_url)
                                case linkzuordnung = "Bild8":
                                    linkBild8 := text(response.result.secure_url)
                                case linkzuordnung = "Bild9":
                                    linkBild9 := text(response.result.secure_url)
                                case linkzuordnung = "Bild10":
                                    linkBild10 := text(response.result.secure_url)
                                default:
                                    alert("fehler in der Zuordnung")
                                end
                            end
                        end
                    end
                end;
                ---
vor dem löschen der Files / Rückgabelink mit files gegenprüfen
                ---;
                let linkfile := [last(split(text(linkAbrechnung), "/")), last(split(text(linkBild1), "/")), last(split(text(linkBild2), "/")), last(split(text(linkBild3), "/")), last(split(text(linkBild4), "/")), last(split(text(linkBild5), "/")), last(split(text(linkBild6), "/")), last(split(text(linkBild7), "/")), last(split(text(linkBild8), "/")), last(split(text(linkBild9), "/")), last(split(text(linkBild10), "/"))];
                let istfile := [last(split(text(Abrechnung), "/")), last(split(text(Bild1), "/")), last(split(text(Bild2), "/")), last(split(text(Bild3), "/")), last(split(text(Bild4), "/")), last(split(text(Bild5), "/")), last(split(text(Bild6), "/")), last(split(text(Bild7), "/")), last(split(text(Bild8), "/")), last(split(text(Bild9), "/")), last(split(text(Bild10), "/"))];
                if concat(istfile) = concat(linkfile) then
                    ---
wenn übereinstimmt dann files löschen
                    ---;
                    Abrechnung := null;
                    Bild1 := null;
                    Bild2 := null;
                    Bild3 := null;
                    Bild4 := null;
                    Bild5 := null;
                    Bild6 := null;
                    Bild7 := null;
                    Bild8 := null;
                    Bild9 := null;
                    Bild10 := null;
                    for i in files(this) do
                        let vUrl := "https://api.ninoxdb.de/v1/teams/" + teamId() + "/databases/" + databaseId() +
                            "/tables/" +
                            tableId(this) +
                            "/records/" +
                            Nr +
                            "/files/" +
                            last(split(text(i), "/"));
                        fx_AnhangLoeschen(text(vUrl))
                    end
                else
                    alert("fehler in der übertragung")
                end
            end
        end
    end
end

Antwort

null

Content aside

  • vor 2 MonatenZuletzt aktiv
  • 26Ansichten
  • 1 Folge bereits