Как выполнить функцию от загруженного пользователем изображения без сохранения его в базе данных Django?

недавно я пытался создать инструмент стеганографии в django, но у меня возникли некоторые проблемы с тем, как выполнить функцию из загруженного пользователем изображения без сохранения изображения в базе данных.

views.py

def steganography(request):
if request.method == 'POST':
    #Encryption
    if 'steg_en' in request.POST:
        cover_image = request.FILES['cover_image']
        secret_message = request.POST['secret_message']
        
        #perform steganography encryption function

        context_sten = {
            #return encrypted image
        }
        
        return render(request, 'steganography.html', context_sten)

    #Decryption
    elif 'steg_de' in request.POST:
        encrypted_image = request.FILES['encrypted_image']

        #perform steganography decryption function

        context_stde = {
            #return decrypted text
        }

        return render(request, 'steganography.html', context_stde)

else:
    return render(request, 'steganography.html')

После выполнения функций стеганографии, будь то шифрование или дешифрование, он вернет вывод в файл steganography.html

steganography.html

<!-- Encryption Input -->    
<form method="post" enctype="multipart/form-data"> 
     {% csrf_token %} 
     <label for="cover_image">Upload your cover image</label> 
     <input type="file" class="form-control" name="cover_image" required>                             
     <label for="secret_message">Enter your secret message</label> 
     <input type="text" class="form-control" name="secret_message" placeholder="Enter your secret message" required> 
                    
     <button type="submit" name="steg_en" class="btn btn-primary">Encrypt</button>
</form>

<!-- Encryption Output -->


<!-- Decryption Input -->
<form method="post" enctype="multipart/form-data"> 
    {% csrf_token %} 
    <label for="encrypted_image">Upload your encrypted image</label> 
    <input type="file" class="form-control" name="encrypted_image" required> 
                 
    <button type="submit" name="steg_de" class="btn btn-primary">Decrypt</button> 
</form>

<!-- Decryption Output -->
  {{ decrypted_text }}

stego.py

Это код стеганографии, на который я ссылаюсь.

Ссылка: https://dev.to/erikwhiting88/let-s-hide-a-secret-message-in-an-image-with-python-and-opencv-1jf5

Вернуться на верх