Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Documentation request]Isolated file upload to adam features #19

Open
enfJoao opened this issue Apr 7, 2019 · 2 comments
Open

[Documentation request]Isolated file upload to adam features #19

enfJoao opened this issue Apr 7, 2019 · 2 comments

Comments

@enfJoao
Copy link

enfJoao commented Apr 7, 2019

I've read quite a few posts about file upload, and tested the moebious forms app, but I can't quite figure how file upload works.

  1. What is the relation between the adam folder name and the entity guid/id?

  2. Could you help create a simple app demo that demonstrates the single file upload feature? For us newbs it's way easier to integrate features without complex environments working around it.

Here's a headstart:

view:

<div>
    <label for="File">Text</label>
    <div>
        <input type="text" id="testText">
    </div>
</div>

<div>
    <label for="File">File (jpeg only)</label>
    <div>
        <input type="file" id="SingleFile" accept=".jpg, .jpeg" value="">
    </div>
</div>

<div>
    <label for="File">Any file</label>
    <div>
        <input type="file" name="Attachments" id="File2_1" value="">
    </div>
</div>

<div>
    <label for="File">Another file</label>
    <div>
        <input type="file" name="Attachments" id="File2_2" value="">
    </div>
</div>

<div>
    <button id="sendData" type="button">SendThis</button>
</div>

<script>
$(document).on("click", "#sendData", sendData);

function getData() {
    return {
        text: $( '#testText' ).val(),
        Files: [],
        user: "@Dnn.User.Username"
    };
}

function sendData() {
    var newItem = getData();
    
    // push file data here
    
    $2sxc(@Dnn.Module.ModuleID).webApi.post("file/ProcessForm", {}, newItem, true);
}
</script>

controller:

using DotNetNuke.Security;
using DotNetNuke.Web.Api;
using System.Web.Http;
using ToSic.SexyContent.WebApi;
using System.Collections.Generic;
using System;
using System.Linq;
using System.Web.Compilation;
using System.Runtime.CompilerServices;
using DotNetNuke.Services.Mail;
using Newtonsoft.Json;
using System.IO;

public class fileController : SxcApiController
{
    [HttpPost]
    [DnnModuleAuthorize(AccessLevel = SecurityAccessLevel.Anonymous)]
    [ValidateAntiForgeryToken]
    public void ProcessForm([FromBody]Dictionary<string,object> contactFormRequest)
    {
        contactFormRequest = new Dictionary<string, object>(contactFormRequest, StringComparer.OrdinalIgnoreCase);

        var guid = Guid.NewGuid();
        contactFormRequest.Add("EntityGuid", guid);
        App.Data.Create("demoData", contactFormRequest);

        var files = new List<ToSic.Sxc.Adam.IFile>();
        foreach(var file in ((Newtonsoft.Json.Linq.JArray)contactFormRequest["Files"]).ToObject<IEnumerable<Dictionary<string, string>>>())
        {
            var data = Convert.FromBase64String((file["Encoded"]).Split(',')[1]);
            files.Add(SaveInAdam(stream: new MemoryStream(data), fileName: file["Name"], contentType: "demoData", guid: guid, field: file["Field"]));
        }
    }
}
@iJungleboy
Copy link
Contributor

I like the idea, i'll see where this could be integrated. It will take ca. 2-3 weeks though, because I'm currently swamped with other priorities.

@enfJoao
Copy link
Author

enfJoao commented Apr 8, 2019

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants